From 74089032ff8b335d1bee7686c7e2dcbdf4506ea0 Mon Sep 17 00:00:00 2001 From: "jst%mozilla.jstenback.com" Date: Thu, 29 Apr 2004 23:34:19 +0000 Subject: [PATCH] Fixing bug 240543. Hiding some nsIPref* API bloatyness in nsContentUtils. r=caillon@aillon.org, sr=peterv@propagandism.org git-svn-id: svn://10.0.0.236/trunk@155712 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/public/nsContentUtils.h | 26 +- mozilla/content/base/src/nsContentUtils.cpp | 110 ++++++ mozilla/content/base/src/nsDocument.cpp | 13 +- mozilla/content/base/src/nsDocumentViewer.cpp | 36 +- .../base/src/nsPlainTextSerializer.cpp | 31 +- mozilla/content/base/src/nsPrintEngine.cpp | 37 +- mozilla/content/base/src/nsSelection.cpp | 25 +- .../events/public/nsIEventStateManager.h | 5 +- .../events/src/nsEventListenerManager.cpp | 2 +- .../events/src/nsEventStateManager.cpp | 262 ++++++------- .../content/events/src/nsEventStateManager.h | 31 +- .../html/content/src/nsFormSubmission.cpp | 10 +- .../html/content/src/nsHTMLImageElement.cpp | 13 +- .../html/document/src/nsHTMLContentSink.cpp | 52 +-- .../html/document/src/nsHTMLDocument.cpp | 66 ++-- .../html/document/src/nsImageDocument.cpp | 9 +- .../content/xbl/src/nsXBLProtoImplMember.h | 2 +- .../content/xbl/src/nsXBLPrototypeHandler.cpp | 11 +- mozilla/content/xbl/src/nsXBLService.cpp | 8 +- .../content/xml/content/src/nsXMLElement.cpp | 31 +- .../xml/document/src/nsXMLContentSink.cpp | 4 +- .../xml/document/src/nsXMLContentSink.h | 2 +- .../xml/document/src/nsXMLDocument.cpp | 1 + .../xml/document/src/nsXMLPrettyPrinter.cpp | 13 +- mozilla/content/xul/content/src/Makefile.in | 1 + .../xul/content/src/nsXULPopupListener.cpp | 17 +- .../xul/document/src/nsXULPrototypeCache.cpp | 87 +++-- mozilla/content/xul/templates/src/Makefile.in | 1 + mozilla/dom/src/base/nsGlobalWindow.cpp | 116 ++---- mozilla/dom/src/base/nsGlobalWindow.h | 6 +- .../dom/src/base/nsGlobalWindowCommands.cpp | 2 +- mozilla/dom/src/base/nsJSEnvironment.cpp | 83 ++--- mozilla/layout/base/nsCSSFrameConstructor.cpp | 13 +- mozilla/layout/base/nsDocumentViewer.cpp | 36 +- mozilla/layout/base/nsPresContext.cpp | 345 ++++++++++-------- mozilla/layout/base/nsPresContext.h | 3 - mozilla/layout/base/nsPresShell.cpp | 75 ++-- mozilla/layout/base/public/nsIPresContext.h | 3 - mozilla/layout/base/public/nsPresContext.h | 3 - mozilla/layout/base/src/Makefile.in | 2 + mozilla/layout/base/src/nsPresContext.cpp | 345 ++++++++++-------- mozilla/layout/base/src/nsPresContext.h | 2 - mozilla/layout/generic/nsFrame.cpp | 8 +- mozilla/layout/generic/nsFrameSetFrame.cpp | 104 ++---- mozilla/layout/generic/nsFrameSetFrame.h | 9 +- mozilla/layout/generic/nsHTMLReflowState.cpp | 35 +- mozilla/layout/generic/nsImageFrame.cpp | 44 +-- mozilla/layout/generic/nsImageFrame.h | 3 +- mozilla/layout/generic/nsObjectFrame.cpp | 11 +- mozilla/layout/generic/nsSelection.cpp | 25 +- .../layout/generic/nsSimplePageSequence.cpp | 25 +- mozilla/layout/generic/nsTextFrame.cpp | 169 +++++---- mozilla/layout/generic/nsTextTransformer.cpp | 42 +-- mozilla/layout/generic/nsTextTransformer.h | 11 +- mozilla/layout/html/base/src/nsFrame.cpp | 8 +- .../html/base/src/nsHTMLReflowState.cpp | 35 +- mozilla/layout/html/base/src/nsImageFrame.cpp | 44 +-- mozilla/layout/html/base/src/nsImageFrame.h | 3 +- .../layout/html/base/src/nsObjectFrame.cpp | 11 +- mozilla/layout/html/base/src/nsPresShell.cpp | 75 ++-- .../html/base/src/nsSimplePageSequence.cpp | 25 +- mozilla/layout/html/base/src/nsTextFrame.cpp | 169 +++++---- .../html/base/src/nsTextTransformer.cpp | 42 +-- .../layout/html/base/src/nsTextTransformer.h | 11 +- .../html/document/src/nsFrameSetFrame.cpp | 104 ++---- .../html/document/src/nsFrameSetFrame.h | 9 +- mozilla/layout/html/style/src/Makefile.in | 2 + .../html/style/src/nsCSSFrameConstructor.cpp | 13 +- mozilla/layout/printing/nsPrintEngine.cpp | 37 +- .../src/libart/nsSVGLibartPathGeometry.cpp | 1 - .../svg/renderer/src/libart/nsSVGStroke.cpp | 1 - mozilla/layout/xul/base/src/nsBoxFrame.cpp | 9 +- .../layout/xul/base/src/nsMenuBarListener.cpp | 18 +- mozilla/layout/xul/base/src/nsMenuFrame.cpp | 8 +- mozilla/layout/xul/base/src/nsSliderFrame.cpp | 22 +- .../layout/xul/base/src/nsTextBoxFrame.cpp | 23 +- .../xul/base/src/nsXULTooltipListener.cpp | 66 ++-- .../xul/base/src/nsXULTooltipListener.h | 8 +- 78 files changed, 1417 insertions(+), 1753 deletions(-) diff --git a/mozilla/content/base/public/nsContentUtils.h b/mozilla/content/base/public/nsContentUtils.h index d99f2f2c00a..fdb4b0e1c01 100644 --- a/mozilla/content/base/public/nsContentUtils.h +++ b/mozilla/content/base/public/nsContentUtils.h @@ -50,6 +50,7 @@ #include "nsIScriptContext.h" #include "nsCOMArray.h" #include "nsIStatefulFrame.h" +#include "nsIPref.h" class nsIXPConnect; class nsIContent; @@ -66,6 +67,8 @@ class nsIURI; class imgIDecoderObserver; class imgIRequest; class imgILoader; +class nsIPrefBranch; +class nsIPref; class nsContentUtils { @@ -283,6 +286,23 @@ public: nsINodeInfoManager* aNodeInfoManager, nsINodeInfo** aNodeInfo); + static nsAdoptingCString GetCharPref(const char *aPref); + static PRPackedBool GetBoolPref(const char *aPref, + PRBool aDefault = PR_FALSE); + static PRInt32 GetIntPref(const char *aPref, PRInt32 aDefault = 0); + static nsAdoptingString GetLocalizedStringPref(const char *aPref); + static nsAdoptingString GetStringPref(const char *aPref); + static void RegisterPrefCallback(const char *aPref, + PrefChangedFunc aCallback, + void * aClosure); + static void UnregisterPrefCallback(const char *aPref, + PrefChangedFunc aCallback, + void * aClosure); + static nsIPrefBranch *GetPrefBranch() + { + return sPrefBranch; + } + static nsresult GetDocumentAndPrincipal(nsIDOMNode* aNode, nsIDocument** aDocument, nsIPrincipal** aPrincipal); @@ -336,8 +356,12 @@ private: static nsIIOService *sIOService; + static nsIPrefBranch *sPrefBranch; + + static nsIPref *sPref; + static imgILoader* sImgLoader; - + static PRBool sInitialized; }; diff --git a/mozilla/content/base/src/nsContentUtils.cpp b/mozilla/content/base/src/nsContentUtils.cpp index 9a93ed38a6d..2f4f9303609 100644 --- a/mozilla/content/base/src/nsContentUtils.cpp +++ b/mozilla/content/base/src/nsContentUtils.cpp @@ -46,6 +46,9 @@ #include "nsAString.h" #include "nsPrintfCString.h" #include "nsUnicharUtils.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" +#include "nsIPrefLocalizedString.h" #include "nsIServiceManagerUtils.h" #include "nsIScriptGlobalObject.h" #include "nsIScriptContext.h" @@ -82,6 +85,7 @@ #include "nsIForm.h" #include "nsIFormControl.h" #include "nsHTMLAtoms.h" +#include "nsISupportsPrimitives.h" #include "nsLayoutAtoms.h" #include "imgIDecoderObserver.h" #include "imgIRequest.h" @@ -100,6 +104,8 @@ nsIThreadJSContextStack *nsContentUtils::sThreadJSContextStack = nsnull; nsIParserService *nsContentUtils::sParserService = nsnull; nsINameSpaceManager *nsContentUtils::sNameSpaceManager = nsnull; nsIIOService *nsContentUtils::sIOService = nsnull; +nsIPrefBranch *nsContentUtils::sPrefBranch = nsnull; +nsIPref *nsContentUtils::sPref = nsnull; imgILoader *nsContentUtils::sImgLoader = nsnull; PRBool nsContentUtils::sInitialized = PR_FALSE; @@ -118,6 +124,12 @@ nsContentUtils::Init() &sSecurityManager); NS_ENSURE_SUCCESS(rv, rv); + // It's ok to not have a pref service. + CallGetService(NS_PREFSERVICE_CONTRACTID, &sPrefBranch); + + // It's ok to not have prefs too. + CallGetService(NS_PREF_CONTRACTID, &sPref); + rv = NS_GetNameSpaceManager(&sNameSpaceManager); NS_ENSURE_SUCCESS(rv, rv); @@ -1677,6 +1689,104 @@ nsContentUtils::LoadImage(nsIURI* aURI, nsIDocument* aLoadingDocument, aRequest); } +// static +nsAdoptingCString +nsContentUtils::GetCharPref(const char *aPref) +{ + nsAdoptingCString result; + + if (sPrefBranch) { + sPrefBranch->GetCharPref(aPref, getter_Copies(result)); + } + + return result; +} + +// static +PRPackedBool +nsContentUtils::GetBoolPref(const char *aPref, PRBool aDefault) +{ + PRBool result; + + if (!sPrefBranch || + NS_FAILED(sPrefBranch->GetBoolPref(aPref, &result))) { + result = aDefault; + } + + return (PRPackedBool)result; +} + +// static +PRInt32 +nsContentUtils::GetIntPref(const char *aPref, PRInt32 aDefault) +{ + PRInt32 result; + + if (!sPrefBranch || + NS_FAILED(sPrefBranch->GetIntPref(aPref, &result))) { + result = aDefault; + } + + return result; +} + +// static +nsAdoptingString +nsContentUtils::GetLocalizedStringPref(const char *aPref) +{ + nsAdoptingString result; + + if (sPrefBranch) { + nsCOMPtr prefLocalString; + sPrefBranch->GetComplexValue(aPref, NS_GET_IID(nsIPrefLocalizedString), + getter_AddRefs(prefLocalString)); + if (prefLocalString) { + prefLocalString->GetData(getter_Copies(result)); + } + } + + return result; +} + +// static +nsAdoptingString +nsContentUtils::GetStringPref(const char *aPref) +{ + nsAdoptingString result; + + if (sPrefBranch) { + nsCOMPtr theString; + sPrefBranch->GetComplexValue(aPref, NS_GET_IID(nsISupportsString), + getter_AddRefs(theString)); + if (theString) { + theString->ToString(getter_Copies(result)); + } + } + + return result; +} + +// static +void +nsContentUtils::RegisterPrefCallback(const char *aPref, + PrefChangedFunc aCallback, + void * aClosure) +{ + if (sPref) + sPref->RegisterCallback(aPref, aCallback, aClosure); +} + +// static +void +nsContentUtils::UnregisterPrefCallback(const char *aPref, + PrefChangedFunc aCallback, + void * aClosure) +{ + if (sPref) + sPref->UnregisterCallback(aPref, aCallback, aClosure); +} + + void nsCxPusher::Push(nsISupports *aCurrentTarget) { diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index 99257060358..7680cf656f8 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -115,14 +115,13 @@ static NS_DEFINE_CID(kDOMEventGroupCID, NS_DOMEVENTGROUP_CID); #include "nsHTMLAtoms.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" - #include "nsScriptEventManager.h" #include "nsIXPathEvaluatorInternal.h" #include "nsIElementFactory.h" #include "nsIParserService.h" +#include "nsIScriptContext.h" + #ifdef DEBUG #include "nsICharsetAlias.h" static NS_DEFINE_CID(kCharsetAliasCID, NS_CHARSETALIAS_CID); @@ -4175,13 +4174,7 @@ nsDocument::RetrieveRelevantHeaders(nsIChannel *aChannel) } if (!have_contentLanguage) { - nsCOMPtr prefBranch = - do_GetService(NS_PREFSERVICE_CONTRACTID); - - if (prefBranch) { - prefBranch->GetCharPref("intl.accept_languages", - getter_Copies(mContentLanguage)); - } + mContentLanguage = nsContentUtils::GetCharPref("intl.accept_languages"); } } diff --git a/mozilla/content/base/src/nsDocumentViewer.cpp b/mozilla/content/base/src/nsDocumentViewer.cpp index d5bc8eb39fe..c87abfa35be 100644 --- a/mozilla/content/base/src/nsDocumentViewer.cpp +++ b/mozilla/content/base/src/nsDocumentViewer.cpp @@ -81,9 +81,6 @@ #include "nsIViewManager.h" #include "nsIView.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" -#include "nsIPrefLocalizedString.h" #include "nsIPageSequenceFrame.h" #include "nsIURL.h" #include "nsNetUtil.h" @@ -2348,7 +2345,8 @@ SetChildTextZoom(nsIMarkupDocumentViewer* aChild, void* aClosure) aChild->SetTextZoom(textZoomInfo->mTextZoom); } -NS_IMETHODIMP DocumentViewerImpl::SetTextZoom(float aTextZoom) +NS_IMETHODIMP +DocumentViewerImpl::SetTextZoom(float aTextZoom) { if (mDeviceContext) { float oldTextZoom = 1.0; // just in case mDeviceContext doesn't implement @@ -2367,7 +2365,8 @@ NS_IMETHODIMP DocumentViewerImpl::SetTextZoom(float aTextZoom) return CallChildren(SetChildTextZoom, &textZoomInfo); } -NS_IMETHODIMP DocumentViewerImpl::GetTextZoom(float* aTextZoom) +NS_IMETHODIMP +DocumentViewerImpl::GetTextZoom(float* aTextZoom) { NS_ENSURE_ARG_POINTER(aTextZoom); @@ -2379,35 +2378,18 @@ NS_IMETHODIMP DocumentViewerImpl::GetTextZoom(float* aTextZoom) return NS_OK; } -// XXX: SEMANTIC CHANGE! -// returns a copy of the string. Caller is responsible for freeing result -// using Recycle(aDefaultCharacterSet) -NS_IMETHODIMP DocumentViewerImpl::GetDefaultCharacterSet(nsACString& aDefaultCharacterSet) +NS_IMETHODIMP +DocumentViewerImpl::GetDefaultCharacterSet(nsACString& aDefaultCharacterSet) { NS_ENSURE_STATE(mContainer); if (mDefaultCharacterSet.IsEmpty()) { - nsXPIDLString defCharset; - - nsCOMPtr webShell; - webShell = do_QueryInterface(mContainer); - if (webShell) - { - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - nsCOMPtr prefLocalString; - prefBranch->GetComplexValue("intl.charset.default", - NS_GET_IID(nsIPrefLocalizedString), - getter_AddRefs(prefLocalString)); - if (prefLocalString) { - prefLocalString->GetData(getter_Copies(defCharset)); - } - } - } + const nsAdoptingString& defCharset = + nsContentUtils::GetLocalizedStringPref("intl.charset.default"); if (!defCharset.IsEmpty()) - CopyUCS2toASCII(defCharset, mDefaultCharacterSet); + LossyCopyUTF16toASCII(defCharset, mDefaultCharacterSet); else mDefaultCharacterSet.Assign(NS_LITERAL_CSTRING("ISO-8859-1")); } diff --git a/mozilla/content/base/src/nsPlainTextSerializer.cpp b/mozilla/content/base/src/nsPlainTextSerializer.cpp index 709c84264aa..0e7185216b9 100644 --- a/mozilla/content/base/src/nsPlainTextSerializer.cpp +++ b/mozilla/content/base/src/nsPlainTextSerializer.cpp @@ -40,8 +40,6 @@ #include "nsPlainTextSerializer.h" #include "nsILineBreakerFactory.h" #include "nsLWBrkCIID.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" #include "nsIServiceManager.h" #include "nsHTMLAtoms.h" #include "nsIDOMText.h" @@ -204,33 +202,30 @@ nsPlainTextSerializer::Init(PRUint32 aFlags, PRUint32 aWrapColumn, mLineBreakDue = PR_FALSE; mFloatingLines = -1; - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (!prefBranch) { - NS_WARNING("Could not get a pref branch!"); - return NS_OK; - } - - PRBool tempBool = PR_FALSE; if (mFlags & nsIDocumentEncoder::OutputFormatted) { // Get some prefs that controls how we do formatted output - prefBranch->GetBoolPref(PREF_STRUCTS, &tempBool); - mStructs = tempBool; - prefBranch->GetIntPref(PREF_HEADER_STRATEGY, &mHeaderStrategy); + mStructs = nsContentUtils::GetBoolPref(PREF_STRUCTS, mStructs); + + mHeaderStrategy = + nsContentUtils::GetIntPref(PREF_HEADER_STRATEGY, mHeaderStrategy); + // The quotesPreformatted pref is a temporary measure. See bug 69638. - prefBranch->GetBoolPref("editor.quotesPreformatted", &tempBool); - mQuotesPreformatted = tempBool; + mQuotesPreformatted = + nsContentUtils::GetBoolPref("editor.quotesPreformatted", + mQuotesPreformatted); + // DontWrapAnyQuotes is set according to whether plaintext mail // is wrapping to window width -- see bug 134439. // We'll only want this if we're wrapping and formatted. if (mFlags & nsIDocumentEncoder::OutputWrap || mWrapColumn > 0) { - prefBranch->GetBoolPref("mail.compose.wrap_to_window_width", &tempBool); - mDontWrapAnyQuotes = tempBool; + mDontWrapAnyQuotes = + nsContentUtils::GetBoolPref("mail.compose.wrap_to_window_width", + mDontWrapAnyQuotes); } } // XXX We should let the caller pass this in. - prefBranch->GetBoolPref("browser.frames.enabled", &tempBool); - if (tempBool) { + if (nsContentUtils::GetBoolPref("browser.frames.enabled")) { mFlags &= ~nsIDocumentEncoder::OutputNoFramesContent; } else { diff --git a/mozilla/content/base/src/nsPrintEngine.cpp b/mozilla/content/base/src/nsPrintEngine.cpp index 4316ba8dd97..551e4b1983f 100644 --- a/mozilla/content/base/src/nsPrintEngine.cpp +++ b/mozilla/content/base/src/nsPrintEngine.cpp @@ -142,8 +142,6 @@ static const char kPrintingPromptService[] = "@mozilla.org/embedcomp/printingpro #include "nsIViewManager.h" #include "nsIView.h" -#include "nsIPrefService.h" -#include "nsIPrefBranch.h" #include "nsIPageSequenceFrame.h" #include "nsIURL.h" #include "nsIContentViewerEdit.h" @@ -738,13 +736,8 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings, mPrt->mPrintSettings->GetPrintSilent(&printSilently); // Check prefs for a default setting as to whether we should print silently - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - PRBool alwaysPrintSilent; - if (NS_SUCCEEDED(prefBranch->GetBoolPref("print.always_print_silent", &alwaysPrintSilent))) { - printSilently = alwaysPrintSilent; - } - } + printSilently = nsContentUtils::GetBoolPref("print.always_print_silent", + printSilently); // Ask dialog to be Print Shown via the Plugable Printing Dialog Service // This service is for the Print Dialog and the Print Progress Dialog @@ -1586,10 +1579,7 @@ nsPrintEngine::CheckDocumentForPPCaching() // Only check if it is the first time into PP if (!mOldPrtPreview) { // First check the Pref - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - prefBranch->GetBoolPref("print.always_cache_old_pres", &cacheOldPres); - } + cacheOldPres = nsContentUtils::GetBoolPref("print.always_cache_old_pres"); // Temp fix for FrameSet Print Preview Bugs if (!cacheOldPres && mPrt->mPrintObject->mFrameType == eFrameSet) { @@ -1660,10 +1650,8 @@ nsPrintEngine::ShowPrintProgress(PRBool aIsForPrinting, PRBool& aDoNotify) // if it is already being shown then don't bother to find out if it should be // so skip this and leave mShowProgressDialog set to FALSE if (!mPrt->mProgressDialogIsShown) { - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - prefBranch->GetBoolPref("print.show_print_progress", &mPrt->mShowProgressDialog); - } + mPrt->mShowProgressDialog = + nsContentUtils::GetBoolPref("print.show_print_progress"); } // Turning off the showing of Print Progress in Prefs overrides @@ -2218,9 +2206,8 @@ nsresult nsPrintEngine::CleanupOnFailure(nsresult aResult, PRBool aIsPrinting) void nsPrintEngine::ShowPrintErrorDialog(nsresult aPrintError, PRBool aIsPrinting) { - nsresult rv; - - PR_PL(("nsPrintEngine::ShowPrintErrorDialog(nsresult aPrintError=%lx, PRBool aIsPrinting=%d)\n", (long)rv, (int)aIsPrinting)); + + PR_PL(("nsPrintEngine::ShowPrintErrorDialog(nsresult aPrintError=%lx, PRBool aIsPrinting=%d)\n", (long)aPrintError, (int)aIsPrinting)); static NS_DEFINE_CID(kCStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); nsCOMPtr stringBundleService = do_GetService(kCStringBundleServiceCID); @@ -2230,7 +2217,7 @@ nsPrintEngine::ShowPrintErrorDialog(nsresult aPrintError, PRBool aIsPrinting) return; } nsCOMPtr myStringBundle; - rv = stringBundleService->CreateBundle(NS_ERROR_GFX_PRINTER_BUNDLE_URL, getter_AddRefs(myStringBundle)); + nsresult rv = stringBundleService->CreateBundle(NS_ERROR_GFX_PRINTER_BUNDLE_URL, getter_AddRefs(myStringBundle)); if (NS_FAILED(rv)) { PR_PL(("ShowPrintErrorDialog(): CreateBundle() failure for NS_ERROR_GFX_PRINTER_BUNDLE_URL, rv=%lx\n", (long)rv)); return; @@ -5017,14 +5004,10 @@ PRBool nsPrintEngine::mIsDoingRuntimeTesting = PR_FALSE; void nsPrintEngine::InitializeTestRuntimeError() { - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - mIsDoingRuntimeTesting = PR_FALSE; - prefBranch->GetBoolPref("print.doing_runtime_error_checking", &mIsDoingRuntimeTesting); - } + mIsDoingRuntimeTesting = + nsContentUtils::GetBoolPref("print.doing_runtime_error_checking"); mLayoutDebugObj = do_GetService("@mozilla.org/debug/debugobject;1"); - } PRBool diff --git a/mozilla/content/base/src/nsSelection.cpp b/mozilla/content/base/src/nsSelection.cpp index 26ba2b82f4a..838100bfbbe 100644 --- a/mozilla/content/base/src/nsSelection.cpp +++ b/mozilla/content/base/src/nsSelection.cpp @@ -68,8 +68,6 @@ #include "nsISelectionListener.h" #include "nsIContentIterator.h" #include "nsIDocumentEncoder.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" // for IBMBIDI #include "nsFrameTraversal.h" @@ -929,24 +927,17 @@ nsSelection::nsSelection() mSelectingTableCellMode = 0; mSelectedCellIndex = 0; - - // Check to see if the autocopy pref is enabled // and add the autocopy listener if it is - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - static char pref[] = "clipboard.autocopy"; - PRBool autoCopy = PR_FALSE; - if (NS_SUCCEEDED(prefBranch->GetBoolPref(pref, &autoCopy)) && autoCopy) { - nsCOMPtr autoCopyService = - do_GetService("@mozilla.org/autocopy;1"); + if (nsContentUtils::GetBoolPref("clipboard.autocopy")) { + nsCOMPtr autoCopyService = + do_GetService("@mozilla.org/autocopy;1"); - if (autoCopyService) { - PRInt8 index = - GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); - if (mDomSelections[index]) { - autoCopyService->Listen(mDomSelections[index]); - } + if (autoCopyService) { + PRInt8 index = + GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); + if (mDomSelections[index]) { + autoCopyService->Listen(mDomSelections[index]); } } } diff --git a/mozilla/content/events/public/nsIEventStateManager.h b/mozilla/content/events/public/nsIEventStateManager.h index 7691e995865..32e53144dba 100644 --- a/mozilla/content/events/public/nsIEventStateManager.h +++ b/mozilla/content/events/public/nsIEventStateManager.h @@ -101,9 +101,8 @@ public: NS_IMETHOD ContentRemoved(nsIContent* aContent) = 0; NS_IMETHOD EventStatusOK(nsGUIEvent* aEvent, PRBool *aOK) = 0; - // This is called when browse with caret changes on the fly - NS_IMETHOD GetBrowseWithCaret(PRBool *aBrowseWithCaret) = 0; - NS_IMETHOD ResetBrowseWithCaret(PRBool *aBrowseWithCaret) = 0; + // Return whether browse with caret is enabled or not + virtual PRBool GetBrowseWithCaret() = 0; // This is called after find text or when a cursor movement key is pressed // If aCanFocusDoc == PR_TRUE, the current document will be focused if caret is not on a focusable element diff --git a/mozilla/content/events/src/nsEventListenerManager.cpp b/mozilla/content/events/src/nsEventListenerManager.cpp index 92e023ab58d..6bfe24d665c 100644 --- a/mozilla/content/events/src/nsEventListenerManager.cpp +++ b/mozilla/content/events/src/nsEventListenerManager.cpp @@ -1593,7 +1593,7 @@ nsEventListenerManager::FlipCaptureBit(PRInt32 aEventTypes, PRBool aInitCapture) { EventArrayType arrayType = eEventArrayType_None; - PRUint8 bits; + PRUint8 bits = 0; if (aEventTypes & nsIDOMNSEvent::MOUSEDOWN) { arrayType = eEventArrayType_Mouse; diff --git a/mozilla/content/events/src/nsEventStateManager.cpp b/mozilla/content/events/src/nsEventStateManager.cpp index aaa83c03ba6..75197dd54c0 100644 --- a/mozilla/content/events/src/nsEventStateManager.cpp +++ b/mozilla/content/events/src/nsEventStateManager.cpp @@ -81,9 +81,9 @@ #include "nsIDocShellTreeNode.h" #include "nsIWebNavigation.h" #include "nsIContentViewer.h" +#include "nsIPrefBranchInternal.h" #include "nsIServiceManager.h" -#include "nsIPrefService.h" #include "nsIScriptSecurityManager.h" #include "nsIChromeEventHandler.h" @@ -209,40 +209,37 @@ CurrentEventShepherd::~CurrentEventShepherd() /******************************************************************/ nsEventStateManager::nsEventStateManager() - : mGestureDownPoint(0,0), + : mLockCursor(0), + mCurrentTarget(nsnull), + mLastMouseOverFrame(nsnull), + mLastDragOverFrame(nsnull), + // init d&d gesture state machine variables + mIsTrackingDragGesture(PR_FALSE), + mGestureDownPoint(0,0), mGestureDownRefPoint(0,0), + mGestureDownFrame(nsnull), mCurrentFocusFrame(nsnull), + mLastFocusedWith(eEventFocusedByUnknown), + mCurrentTabIndex(0), + mCurrentEvent(0), + mPresContext(nsnull), + mLClickCount(0), + mMClickCount(0), + mRClickCount(0), + mConsumeFocusEvents(PR_FALSE), + mNormalLMouseEventInProcess(PR_FALSE), m_haveShutdown(PR_FALSE), mClearedFrameRefsDuringEvent(PR_FALSE), - mDOMEventLevel(0) -{ - mLastMouseOverFrame = nsnull; - mLastDragOverFrame = nsnull; - mCurrentTarget = nsnull; - - mConsumeFocusEvents = PR_FALSE; - mLockCursor = 0; - mCurrentEvent = 0; - - // init d&d gesture state machine variables - mIsTrackingDragGesture = PR_FALSE; - mGestureDownFrame = nsnull; - - mLClickCount = 0; - mMClickCount = 0; - mRClickCount = 0; - mLastFocusedWith = eEventFocusedByUnknown; - mPresContext = nsnull; - mCurrentTabIndex = 0; - mAccessKeys = nsnull; - mBrowseWithCaret = PR_FALSE; - mNormalLMouseEventInProcess = PR_FALSE; - mTabbedThroughDocument = PR_FALSE; - + mBrowseWithCaret(PR_FALSE), + mTabbedThroughDocument(PR_FALSE), + mDOMEventLevel(0), + mAccessKeys(nsnull) #ifdef CLICK_HOLD_CONTEXT_MENUS - mEventDownWidget = nsnull; + , + mEventDownWidget(nsnull), + mEventPresContext(nsnull) #endif - +{ ++sESMInstanceCount; } @@ -252,41 +249,44 @@ nsEventStateManager::Init() nsresult rv; nsCOMPtr observerService = do_GetService("@mozilla.org/observer-service;1", &rv); - if (NS_SUCCEEDED(rv)) - { - observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_TRUE); - } + NS_ENSURE_SUCCESS(rv, rv); - rv = getPrefBranch(); + observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_TRUE); - if (NS_SUCCEEDED(rv)) { + nsCOMPtr prefBranch = + do_QueryInterface(nsContentUtils::GetPrefBranch()); + + if (prefBranch) { if (sESMInstanceCount == 1) { - mPrefBranch->GetBoolPref("nglayout.events.dispatchLeftClickOnly", - &sLeftClickOnly); + sLeftClickOnly = + nsContentUtils::GetBoolPref("nglayout.events.dispatchLeftClickOnly", + sLeftClickOnly); - mPrefBranch->GetIntPref("ui.key.generalAccessKey", - &sGeneralAccesskeyModifier); + sGeneralAccesskeyModifier = + nsContentUtils::GetIntPref("ui.key.generalAccessKey", + sGeneralAccesskeyModifier); - mPrefBranch->GetIntPref("accessibility.tabfocus", &sTabFocusModel); + sTabFocusModel = nsContentUtils::GetIntPref("accessibility.tabfocus", + sTabFocusModel); } - mPrefBranch->AddObserver("accessibility.accesskeycausesactivation", this, PR_TRUE); - mPrefBranch->AddObserver("accessibility.browsewithcaret", this, PR_TRUE); - mPrefBranch->AddObserver("accessibility.tabfocus", this, PR_TRUE); - mPrefBranch->AddObserver("nglayout.events.dispatchLeftClickOnly", this, PR_TRUE); - mPrefBranch->AddObserver("ui.key.generalAccessKey", this, PR_TRUE); + prefBranch->AddObserver("accessibility.accesskeycausesactivation", this, PR_TRUE); + prefBranch->AddObserver("accessibility.browsewithcaret", this, PR_TRUE); + prefBranch->AddObserver("accessibility.tabfocus", this, PR_TRUE); + prefBranch->AddObserver("nglayout.events.dispatchLeftClickOnly", this, PR_TRUE); + prefBranch->AddObserver("ui.key.generalAccessKey", this, PR_TRUE); #if 0 - mPrefBranch->AddObserver("mousewheel.withaltkey.action", this, PR_TRUE); - mPrefBranch->AddObserver("mousewheel.withaltkey.numlines", this, PR_TRUE); - mPrefBranch->AddObserver("mousewheel.withaltkey.sysnumlines", this, PR_TRUE); - mPrefBranch->AddObserver("mousewheel.withcontrolkey.action", this, PR_TRUE); - mPrefBranch->AddObserver("mousewheel.withcontrolkey.numlines", this, PR_TRUE); - mPrefBranch->AddObserver("mousewheel.withcontrolkey.sysnumlines", this, PR_TRUE); - mPrefBranch->AddObserver("mousewheel.withnokey.action", this, PR_TRUE); - mPrefBranch->AddObserver("mousewheel.withnokey.numlines", this, PR_TRUE); - mPrefBranch->AddObserver("mousewheel.withnokey.sysnumlines", this, PR_TRUE); - mPrefBranch->AddObserver("mousewheel.withshiftkey.action", this, PR_TRUE); - mPrefBranch->AddObserver("mousewheel.withshiftkey.numlines", this, PR_TRUE); - mPrefBranch->AddObserver("mousewheel.withshiftkey.sysnumlines", this, PR_TRUE); + prefBranch->AddObserver("mousewheel.withaltkey.action", this, PR_TRUE); + prefBranch->AddObserver("mousewheel.withaltkey.numlines", this, PR_TRUE); + prefBranch->AddObserver("mousewheel.withaltkey.sysnumlines", this, PR_TRUE); + prefBranch->AddObserver("mousewheel.withcontrolkey.action", this, PR_TRUE); + prefBranch->AddObserver("mousewheel.withcontrolkey.numlines", this, PR_TRUE); + prefBranch->AddObserver("mousewheel.withcontrolkey.sysnumlines", this, PR_TRUE); + prefBranch->AddObserver("mousewheel.withnokey.action", this, PR_TRUE); + prefBranch->AddObserver("mousewheel.withnokey.numlines", this, PR_TRUE); + prefBranch->AddObserver("mousewheel.withnokey.sysnumlines", this, PR_TRUE); + prefBranch->AddObserver("mousewheel.withshiftkey.action", this, PR_TRUE); + prefBranch->AddObserver("mousewheel.withshiftkey.numlines", this, PR_TRUE); + prefBranch->AddObserver("mousewheel.withshiftkey.sysnumlines", this, PR_TRUE); #endif } @@ -317,9 +317,7 @@ nsEventStateManager::~nsEventStateManager() NS_IF_RELEASE(gLastFocusedDocument); } - if (mAccessKeys) { - delete mAccessKeys; - } + delete mAccessKeys; if (!m_haveShutdown) { Shutdown(); @@ -342,49 +340,35 @@ nsEventStateManager::~nsEventStateManager() nsresult nsEventStateManager::Shutdown() { - if (mPrefBranch) { - mPrefBranch->RemoveObserver("accessibility.accesskeycausesactivation", this); - mPrefBranch->RemoveObserver("accessibility.browsewithcaret", this); - mPrefBranch->RemoveObserver("accessibility.tabfocus", this); - mPrefBranch->RemoveObserver("nglayout.events.dispatchLeftClickOnly", this); - mPrefBranch->RemoveObserver("ui.key.generalAccessKey", this); + nsCOMPtr prefBranch = + do_QueryInterface(nsContentUtils::GetPrefBranch()); + + if (prefBranch) { + prefBranch->RemoveObserver("accessibility.accesskeycausesactivation", this); + prefBranch->RemoveObserver("accessibility.browsewithcaret", this); + prefBranch->RemoveObserver("accessibility.tabfocus", this); + prefBranch->RemoveObserver("nglayout.events.dispatchLeftClickOnly", this); + prefBranch->RemoveObserver("ui.key.generalAccessKey", this); #if 0 - mPrefBranch->RemoveObserver("mousewheel.withshiftkey.action", this); - mPrefBranch->RemoveObserver("mousewheel.withshiftkey.numlines", this); - mPrefBranch->RemoveObserver("mousewheel.withshiftkey.sysnumlines", this); - mPrefBranch->RemoveObserver("mousewheel.withcontrolkey.action", this); - mPrefBranch->RemoveObserver("mousewheel.withcontrolkey.numlines", this); - mPrefBranch->RemoveObserver("mousewheel.withcontrolkey.sysnumlines", this); - mPrefBranch->RemoveObserver("mousewheel.withaltkey.action", this); - mPrefBranch->RemoveObserver("mousewheel.withaltkey.numlines", this); - mPrefBranch->RemoveObserver("mousewheel.withaltkey.sysnumlines", this); - mPrefBranch->RemoveObserver("mousewheel.withnokey.action", this); - mPrefBranch->RemoveObserver("mousewheel.withnokey.numlines", this); - mPrefBranch->RemoveObserver("mousewheel.withnokey.sysnumlines", this); + prefBranch->RemoveObserver("mousewheel.withshiftkey.action", this); + prefBranch->RemoveObserver("mousewheel.withshiftkey.numlines", this); + prefBranch->RemoveObserver("mousewheel.withshiftkey.sysnumlines", this); + prefBranch->RemoveObserver("mousewheel.withcontrolkey.action", this); + prefBranch->RemoveObserver("mousewheel.withcontrolkey.numlines", this); + prefBranch->RemoveObserver("mousewheel.withcontrolkey.sysnumlines", this); + prefBranch->RemoveObserver("mousewheel.withaltkey.action", this); + prefBranch->RemoveObserver("mousewheel.withaltkey.numlines", this); + prefBranch->RemoveObserver("mousewheel.withaltkey.sysnumlines", this); + prefBranch->RemoveObserver("mousewheel.withnokey.action", this); + prefBranch->RemoveObserver("mousewheel.withnokey.numlines", this); + prefBranch->RemoveObserver("mousewheel.withnokey.sysnumlines", this); #endif - mPrefBranch = nsnull; } m_haveShutdown = PR_TRUE; return NS_OK; } -nsresult -nsEventStateManager::getPrefBranch() -{ - nsresult rv = NS_OK; - - if (!mPrefBranch) { - mPrefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); - } - - if (NS_FAILED(rv)) return rv; - - if (!mPrefBranch) return NS_ERROR_FAILURE; - - return NS_OK; -} - NS_IMETHODIMP nsEventStateManager::Observe(nsISupports *aSubject, const char *aTopic, @@ -398,18 +382,22 @@ nsEventStateManager::Observe(nsISupports *aSubject, nsDependentString data(someData); if (data.Equals(NS_LITERAL_STRING("accessibility.accesskeycausesactivation"))) { - mPrefBranch->GetBoolPref("accessibility.accesskeycausesactivation", &sKeyCausesActivation); + sKeyCausesActivation = + nsContentUtils::GetBoolPref("accessibility.accesskeycausesactivation", + sKeyCausesActivation); } else if (data.Equals(NS_LITERAL_STRING("accessibility.browsewithcaret"))) { - PRBool browseWithCaret; - ResetBrowseWithCaret(&browseWithCaret); + ResetBrowseWithCaret(); } else if (data.Equals(NS_LITERAL_STRING("accessibility.tabfocus"))) { - mPrefBranch->GetIntPref("accessibility.tabfocus", &sTabFocusModel); + sTabFocusModel = nsContentUtils::GetIntPref("accessibility.tabfocus", + sTabFocusModel); } else if (data.Equals(NS_LITERAL_STRING("nglayout.events.dispatchLeftClickOnly"))) { - mPrefBranch->GetBoolPref("nglayout.events.dispatchLeftClickOnly", - &sLeftClickOnly); + sLeftClickOnly = + nsContentUtils::GetBoolPref("nglayout.events.dispatchLeftClickOnly", + sLeftClickOnly); } else if (data.Equals(NS_LITERAL_STRING("ui.key.generalAccessKey"))) { - mPrefBranch->GetIntPref("ui.key.generalAccessKey", - &sGeneralAccesskeyModifier); + sGeneralAccesskeyModifier = + nsContentUtils::GetIntPref("ui.key.generalAccessKey", + sGeneralAccesskeyModifier); #if 0 } else if (data.Equals(NS_LITERAL_STRING("mousewheel.withaltkey.action"))) { } else if (data.Equals(NS_LITERAL_STRING("mousewheel.withaltkey.numlines"))) { @@ -678,7 +666,7 @@ nsEventStateManager::PreHandleEvent(nsIPresContext* aPresContext, NS_IF_ADDREF(gLastFocusedDocument); } - ResetBrowseWithCaret(&mBrowseWithCaret); + ResetBrowseWithCaret(); } break; @@ -1989,9 +1977,6 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, break; case NS_MOUSE_SCROLL: if (nsEventStatus_eConsumeNoDefault != *aStatus) { - nsresult rv; - rv = getPrefBranch(); - if (NS_FAILED(rv)) return rv; // Build the preference keys, based on the event properties. nsMouseScrollEvent *msEvent = (nsMouseScrollEvent*) aEvent; @@ -2027,13 +2012,11 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, nsCAutoString sysNumLinesKey(baseKey); sysNumLinesKey.Append(sysnumlinesslot); - PRInt32 action = 0; + PRInt32 action = nsContentUtils::GetIntPref(actionKey.get()); PRInt32 numLines = 0; - PRBool useSysNumLines; + PRBool useSysNumLines = + nsContentUtils::GetBoolPref(sysNumLinesKey.get()); - mPrefBranch->GetIntPref(actionKey.get(), &action); - mPrefBranch->GetBoolPref(sysNumLinesKey.get(), - &useSysNumLines); if (useSysNumLines) { numLines = msEvent->delta; if (msEvent->scrollFlags & nsMouseScrollEvent::kIsFullPage) @@ -2057,8 +2040,7 @@ nsEventStateManager::PostHandleEvent(nsIPresContext* aPresContext, nsCAutoString numLinesKey(baseKey); numLinesKey.Append(numlinesslot); - mPrefBranch->GetIntPref(numLinesKey.get(), - &numLines); + numLines = nsContentUtils::GetIntPref(numLinesKey.get()); bool swapDirs = (numLines < 0); PRInt32 userSize = swapDirs ? -numLines : numLines; @@ -3845,14 +3827,9 @@ nsEventStateManager::GetEventTargetContent(nsEvent* aEvent, NS_IMETHODIMP nsEventStateManager::GetEventRelatedContent(nsIContent** aContent) { - if (mCurrentRelatedContent) { - *aContent = mCurrentRelatedContent; - NS_IF_ADDREF(*aContent); - return NS_OK; - } - - *aContent = nsnull; - return NS_OK; + *aContent = mCurrentRelatedContent; + NS_IF_ADDREF(*aContent); + return NS_OK; } NS_IMETHODIMP @@ -5071,52 +5048,49 @@ nsEventStateManager::SetContentCaretVisible(nsIPresShell* aPresShell, } -NS_IMETHODIMP -nsEventStateManager::GetBrowseWithCaret(PRBool *aBrowseWithCaret) +PRBool +nsEventStateManager::GetBrowseWithCaret() { - NS_ENSURE_ARG_POINTER(aBrowseWithCaret); - *aBrowseWithCaret = mBrowseWithCaret; - return NS_OK; + return mBrowseWithCaret; } -NS_IMETHODIMP -nsEventStateManager::ResetBrowseWithCaret(PRBool *aBrowseWithCaret) +void +nsEventStateManager::ResetBrowseWithCaret() { // This is called when browse with caret changes on the fly // or when a document gets focused - *aBrowseWithCaret = PR_FALSE; - if (!mPresContext) return NS_ERROR_FAILURE; - + if (!mPresContext) + return; + nsCOMPtr pcContainer = mPresContext->GetContainer(); PRInt32 itemType; nsCOMPtr shellItem(do_QueryInterface(pcContainer)); if (!shellItem) - return NS_ERROR_FAILURE; + return; shellItem->GetItemType(&itemType); if (itemType == nsIDocShellTreeItem::typeChrome) - return NS_OK; // Never browse with caret in chrome + return; // Never browse with caret in chrome - mPrefBranch->GetBoolPref("accessibility.browsewithcaret", aBrowseWithCaret); + PRPackedBool browseWithCaret = + nsContentUtils::GetBoolPref("accessibility.browsewithcaret"); - if (mBrowseWithCaret == *aBrowseWithCaret) - return NS_OK; // already set this way, don't change caret at all + if (mBrowseWithCaret == browseWithCaret) + return; // already set this way, don't change caret at all - mBrowseWithCaret = *aBrowseWithCaret; + mBrowseWithCaret = browseWithCaret; nsIPresShell *presShell = mPresContext->GetPresShell(); // Make caret visible or not, depending on what's appropriate if (presShell) { - return SetContentCaretVisible(presShell, mCurrentFocus, - *aBrowseWithCaret && - (!gLastFocusedDocument || - gLastFocusedDocument == mDocument)); + SetContentCaretVisible(presShell, mCurrentFocus, + browseWithCaret && + (!gLastFocusedDocument || + gLastFocusedDocument == mDocument)); } - - return NS_ERROR_FAILURE; } diff --git a/mozilla/content/events/src/nsEventStateManager.h b/mozilla/content/events/src/nsEventStateManager.h index f27614efda8..da9be00a884 100644 --- a/mozilla/content/events/src/nsEventStateManager.h +++ b/mozilla/content/events/src/nsEventStateManager.h @@ -41,7 +41,6 @@ #include "nsIEventStateManager.h" #include "nsGUIEvent.h" #include "nsIContent.h" -#include "nsIPrefBranchInternal.h" #include "nsIObserver.h" #include "nsWeakReference.h" #include "nsHashtable.h" @@ -141,8 +140,8 @@ public: NS_IMETHOD ShiftFocus(PRBool aForward, nsIContent* aStart=nsnull); - NS_IMETHOD GetBrowseWithCaret(PRBool *aBrowseWithCaret); - NS_IMETHOD ResetBrowseWithCaret(PRBool *aBrowseWithCaret); + virtual PRBool GetBrowseWithCaret(); + void ResetBrowseWithCaret(); NS_IMETHOD MoveFocusToCaret(PRBool aCanFocusDoc, PRBool *aIsSelectionWithFocus); NS_IMETHOD MoveCaretToFocus(); @@ -221,7 +220,6 @@ protected: PRBool aScrollPage, PRBool aUseTargetFrame); void ForceViewUpdate(nsIView* aView); - nsresult getPrefBranch(); void DoScrollHistory(PRInt32 direction); void DoScrollTextsize(nsIFrame *aTargetFrame, PRInt32 adjustment); nsresult ChangeTextSize(PRInt32 change); @@ -249,6 +247,8 @@ protected: void BeforeDispatchEvent() { ++mDOMEventLevel; } void AfterDispatchEvent(); + PRInt32 mLockCursor; + //Any frames here must be checked for validity in ClearFrameRefs nsIFrame* mCurrentTarget; nsCOMPtr mCurrentTargetContent; @@ -275,9 +275,7 @@ protected: nsIFrame* mCurrentFocusFrame; PRInt32 mLastFocusedWith; PRInt32 mCurrentTabIndex; - PRBool mConsumeFocusEvents; - PRInt32 mLockCursor; - nsEvent *mCurrentEvent; + nsEvent *mCurrentEvent; // DocShell Traversal Data Memebers nsCOMPtr mLastContentFocus; @@ -295,28 +293,29 @@ protected: PRUint32 mMClickCount; PRUint32 mRClickCount; + PRPackedBool mConsumeFocusEvents; + PRPackedBool mNormalLMouseEventInProcess; - //Hashtable for accesskey support - nsSupportsHashtable *mAccessKeys; - - // For preferences handling - nsCOMPtr mPrefBranch; PRPackedBool m_haveShutdown; // To inform people that dispatched events that frames have been cleared and // they need to drop frame refs PRPackedBool mClearedFrameRefsDuringEvent; + // So we don't have to keep checking accessibility.browsewithcaret pref + PRPackedBool mBrowseWithCaret; + + // Recursion guard for tabbing + PRPackedBool mTabbedThroughDocument; + // The number of events we are currently nested in (currently just applies to // those handlers that care about clearing frame refs) PRInt32 mDOMEventLevel; - // So we don't have to keep checking accessibility.browsewithcaret pref - PRBool mBrowseWithCaret; + //Hashtable for accesskey support + nsSupportsHashtable *mAccessKeys; - // Recursion guard for tabbing - PRBool mTabbedThroughDocument; nsCOMArray mTabbingFromDocShells; #ifdef CLICK_HOLD_CONTEXT_MENUS diff --git a/mozilla/content/html/content/src/nsFormSubmission.cpp b/mozilla/content/html/content/src/nsFormSubmission.cpp index 940ffdd639b..8525584c160 100644 --- a/mozilla/content/html/content/src/nsFormSubmission.cpp +++ b/mozilla/content/html/content/src/nsFormSubmission.cpp @@ -59,8 +59,6 @@ #include "nsIFormProcessor.h" #include "nsIURI.h" #include "nsNetUtil.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" #include "nsLinebreakConverter.h" #include "nsICharsetConverterManager.h" #include "nsICharsetAlias.h" @@ -692,12 +690,8 @@ nsFSMultipartFormData::nsFSMultipartFormData(const nsACString& aCharset, : nsFormSubmission(aCharset, aEncoder, aFormProcessor, aBidiOptions) { // XXX I can't *believe* we have a pref for this. ifdef, anyone? - mBackwardsCompatibleSubmit = PR_FALSE; - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - prefBranch->GetBoolPref("browser.forms.submit.backwards_compatible", - &mBackwardsCompatibleSubmit); - } + mBackwardsCompatibleSubmit = + nsContentUtils::GetBoolPref("browser.forms.submit.backwards_compatible"); } nsresult diff --git a/mozilla/content/html/content/src/nsHTMLImageElement.cpp b/mozilla/content/html/content/src/nsHTMLImageElement.cpp index aa7bc25f13d..77672dff613 100644 --- a/mozilla/content/html/content/src/nsHTMLImageElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLImageElement.cpp @@ -65,8 +65,6 @@ #include "nsGUIEvent.h" #include "nsContentPolicyUtils.h" #include "nsIDOMWindow.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" #include "imgIContainer.h" #include "imgILoader.h" @@ -593,14 +591,9 @@ nsHTMLImageElement::SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, // If caller is not chrome and dom.disable_image_src_set is true, // prevent setting image.src by exiting early - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - PRBool disableImageSrcSet = PR_FALSE; - prefBranch->GetBoolPref("dom.disable_image_src_set", &disableImageSrcSet); - - if (disableImageSrcSet && !nsContentUtils::IsCallerChrome()) { - return NS_OK; - } + if (nsContentUtils::GetBoolPref("dom.disable_image_src_set") && + !nsContentUtils::IsCallerChrome()) { + return NS_OK; } nsCOMPtr oldCurrentRequest = mCurrentRequest; diff --git a/mozilla/content/html/document/src/nsHTMLContentSink.cpp b/mozilla/content/html/document/src/nsHTMLContentSink.cpp index 462670a156c..6c87056503d 100644 --- a/mozilla/content/html/document/src/nsHTMLContentSink.cpp +++ b/mozilla/content/html/document/src/nsHTMLContentSink.cpp @@ -105,9 +105,6 @@ #include "nsISelectElement.h" #include "nsITextAreaElement.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" - #include "nsIStyleSheetLinkingElement.h" #include "nsTimer.h" #include "nsITimer.h" @@ -2154,18 +2151,12 @@ HTMLContentSink::Init(nsIDocument* aDoc, mFlags |= NS_SINK_FLAG_SCRIPT_ENABLED; } - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); + mNotifyOnTimer = + nsContentUtils::GetBoolPref("content.notify.ontimer", PR_TRUE); - PRBool notifyPref = PR_TRUE; - if (prefBranch) { - prefBranch->GetBoolPref("content.notify.ontimer", ¬ifyPref); - } - mNotifyOnTimer = notifyPref; - - mBackoffCount = -1; // never - if (prefBranch) { - prefBranch->GetIntPref("content.notify.backoffcount", &mBackoffCount); - } + // -1 means never + mBackoffCount = + nsContentUtils::GetIntPref("content.notify.backoffcount", -1); // The mNotificationInterval has a dramatic effect on how long it // takes to initially display content for slow connections. @@ -2174,10 +2165,8 @@ HTMLContentSink::Init(nsIDocument* aDoc, // in page load time. If this value is set below 1/10 of second // it starts to impact page load performance. // see bugzilla bug 72138 for more info. - mNotificationInterval = 120000; - if (prefBranch) { - prefBranch->GetIntPref("content.notify.interval", &mNotificationInterval); - } + mNotificationInterval = + nsContentUtils::GetIntPref("content.notify.interval", 120000); // The mMaxTokenProcessingTime controls how long we stay away from // the event loop when processing token. A lower value makes the app @@ -2193,32 +2182,21 @@ HTMLContentSink::Init(nsIDocument* aDoc, // mMaxTokenProcessingTime which does not impact page load // performance. See bugzilla bug 76722 for details. - mMaxTokenProcessingTime = mNotificationInterval * 3; + mMaxTokenProcessingTime = + nsContentUtils::GetIntPref("content.max.tokenizing.time", + mNotificationInterval * 3); - PRBool enableInterruptParsing = PR_TRUE; + // 3/4 second (750000us) default for switching + mDynamicIntervalSwitchThreshold = + nsContentUtils::GetIntPref("content.switch.threshold", 750000); - // 3/4 second default for switching - mDynamicIntervalSwitchThreshold = 750000; - - if (prefBranch) { - prefBranch->GetBoolPref("content.interrupt.parsing", - &enableInterruptParsing); - prefBranch->GetIntPref("content.max.tokenizing.time", - &mMaxTokenProcessingTime); - prefBranch->GetIntPref("content.switch.threshold", - &mDynamicIntervalSwitchThreshold); - } - - if (enableInterruptParsing) { + if (nsContentUtils::GetBoolPref("content.interrupt.parsing", PR_TRUE)) { mFlags |= NS_SINK_FLAG_CAN_INTERRUPT_PARSER; } // Changed from 8192 to greatly improve page loading performance on // large pages. See bugzilla bug 77540. - mMaxTextRun = 8191; - if (prefBranch) { - prefBranch->GetIntPref("content.maxtextrun", &mMaxTextRun); - } + mMaxTextRun = nsContentUtils::GetIntPref("content.maxtextrun", 8191); nsCOMPtr nodeInfo; rv = mNodeInfoManager->GetNodeInfo(nsHTMLAtoms::html, nsnull, diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index db29f2f76a0..109df229943 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -114,7 +114,6 @@ #include "nsICharsetDetectionAdaptor.h" #include "nsCharsetDetectionAdaptorCID.h" #include "nsICharsetAlias.h" -#include "nsIPref.h" #include "nsContentUtils.h" #include "nsJSUtils.h" #include "nsIDocumentCharsetInfo.h" @@ -170,20 +169,8 @@ PRUint32 nsHTMLDocument::gWyciwygSessionCnt = 0; static int PR_CALLBACK MyPrefChangedCallback(const char*aPrefName, void* instance_data) { - nsresult rv; - nsCOMPtr prefs = - do_GetService("@mozilla.org/preferences;1", &rv); - if (NS_FAILED(rv)) { - return 0; - } - - nsXPIDLString detector_name; - - rv = prefs->GetLocalizedUnicharPref("intl.charset.detector", - getter_Copies(detector_name)); - if (NS_FAILED(rv)) { - return 0; - } + const nsAdoptingString& detector_name = + nsContentUtils::GetLocalizedStringPref("intl.charset.detector"); if (detector_name.Length() > 0) { PL_strncpy(g_detector_contractid, NS_CHARSET_DETECTOR_CONTRACTID_BASE, @@ -592,15 +579,13 @@ nsHTMLDocument::UseWeakDocTypeDefault(PRInt32& aCharsetSource, return PR_TRUE; // fallback value in case docshell return error aCharset = NS_LITERAL_CSTRING("ISO-8859-1"); - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID)); - if (prefs) { - nsXPIDLString defCharset; - nsresult rv = prefs->GetLocalizedUnicharPref("intl.charset.default", - getter_Copies(defCharset)); - if (NS_SUCCEEDED(rv) && !defCharset.IsEmpty()) { - CopyUCS2toASCII(defCharset, aCharset); - aCharsetSource = kCharsetFromWeakDocTypeDefault; - } + + const nsAdoptingString& defCharset = + nsContentUtils::GetLocalizedStringPref("intl.charset.default"); + + if (!defCharset.IsEmpty()) { + LossyCopyUTF16toASCII(defCharset, aCharset); + aCharsetSource = kCharsetFromWeakDocTypeDefault; } return PR_TRUE; } @@ -663,24 +648,23 @@ nsHTMLDocument::StartAutodetection(nsIDocShell *aDocShell, nsACString& aCharset, nsCOMPtr cdetflt; nsresult rv_detect; - if(! gInitDetector) { - nsCOMPtr pref(do_GetService(NS_PREF_CONTRACTID)); - if(pref) { - PRUnichar* detector_name = nsnull; - rv_detect = pref->GetLocalizedUnicharPref("intl.charset.detector", - &detector_name); - if(NS_SUCCEEDED(rv_detect)) { - PL_strncpy(g_detector_contractid, NS_CHARSET_DETECTOR_CONTRACTID_BASE, - DETECTOR_CONTRACTID_MAX); - PL_strncat(g_detector_contractid, - NS_ConvertUCS2toUTF8(detector_name).get(), - DETECTOR_CONTRACTID_MAX); - gPlugDetector = PR_TRUE; - PR_FREEIF(detector_name); - } - pref->RegisterCallback("intl.charset.detector", MyPrefChangedCallback, - nsnull); + if(!gInitDetector) { + const nsAdoptingString& detector_name = + nsContentUtils::GetLocalizedStringPref("intl.charset.detector"); + + if(!detector_name.IsEmpty()) { + PL_strncpy(g_detector_contractid, NS_CHARSET_DETECTOR_CONTRACTID_BASE, + DETECTOR_CONTRACTID_MAX); + PL_strncat(g_detector_contractid, + NS_ConvertUTF16toUTF8(detector_name).get(), + DETECTOR_CONTRACTID_MAX); + gPlugDetector = PR_TRUE; } + + nsContentUtils::RegisterPrefCallback("intl.charset.detector", + MyPrefChangedCallback, + nsnull); + gInitDetector = PR_TRUE; } diff --git a/mozilla/content/html/document/src/nsImageDocument.cpp b/mozilla/content/html/document/src/nsImageDocument.cpp index 22ed90ac393..5ca95c446e8 100644 --- a/mozilla/content/html/document/src/nsImageDocument.cpp +++ b/mozilla/content/html/document/src/nsImageDocument.cpp @@ -55,7 +55,6 @@ #include "nsIPresShell.h" #include "nsIPresContext.h" #include "nsStyleContext.h" -#include "nsIPrefService.h" #include "nsAutoPtr.h" #include "nsMediaDocument.h" #include "nsStyleSet.h" @@ -218,12 +217,8 @@ nsImageDocument::Init() nsresult rv = nsMediaDocument::Init(); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - PRBool temp = PR_FALSE; - prefBranch->GetBoolPref(AUTOMATIC_IMAGE_RESIZING_PREF, &temp); - mImageResizingEnabled = temp; - } + mImageResizingEnabled = + nsContentUtils::GetBoolPref(AUTOMATIC_IMAGE_RESIZING_PREF); return NS_OK; } diff --git a/mozilla/content/xbl/src/nsXBLProtoImplMember.h b/mozilla/content/xbl/src/nsXBLProtoImplMember.h index 23b1a89a184..e464876c993 100644 --- a/mozilla/content/xbl/src/nsXBLProtoImplMember.h +++ b/mozilla/content/xbl/src/nsXBLProtoImplMember.h @@ -49,7 +49,7 @@ #include "nsReadableUtils.h" class nsIScriptContext; -class JSRuntime; +struct JSRuntime; class nsIJSRuntimeService; MOZ_DECL_CTOR_COUNTER(nsXBLTextWithLineNumber) diff --git a/mozilla/content/xbl/src/nsXBLPrototypeHandler.cpp b/mozilla/content/xbl/src/nsXBLPrototypeHandler.cpp index 8fef2c562d0..f6f5921544e 100644 --- a/mozilla/content/xbl/src/nsXBLPrototypeHandler.cpp +++ b/mozilla/content/xbl/src/nsXBLPrototypeHandler.cpp @@ -39,6 +39,7 @@ #include "nsCOMPtr.h" #include "nsXBLPrototypeHandler.h" #include "nsXBLPrototypeBinding.h" +#include "nsContentUtils.h" #include "nsIContent.h" #include "nsIAtom.h" #include "nsIDOMKeyEvent.h" @@ -65,8 +66,6 @@ #include "nsPIDOMWindow.h" #include "nsPIWindowRoot.h" #include "nsIDOMWindowInternal.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" #include "nsIServiceManager.h" #include "nsXPIDLString.h" #include "nsReadableUtils.h" @@ -193,11 +192,9 @@ nsXBLPrototypeHandler::InitAccessKeys() #endif // Get the menu access key value from prefs, overriding the default: - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - prefBranch->GetIntPref("ui.key.menuAccessKey", &kMenuAccessKey); - prefBranch->GetIntPref("ui.key.accelKey", &kAccelKey); - } + kMenuAccessKey = + nsContentUtils::GetIntPref("ui.key.menuAccessKey", kMenuAccessKey); + kAccelKey = nsContentUtils::GetIntPref("ui.key.accelKey", kAccelKey); } nsresult diff --git a/mozilla/content/xbl/src/nsXBLService.cpp b/mozilla/content/xbl/src/nsXBLService.cpp index cdd763195d4..3763a331ce1 100644 --- a/mozilla/content/xbl/src/nsXBLService.cpp +++ b/mozilla/content/xbl/src/nsXBLService.cpp @@ -79,9 +79,6 @@ #include "nsISyncLoadDOMService.h" #include "nsIDOM3Node.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" - #include "nsIPresShell.h" #include "nsIDocumentObserver.h" #include "nsFrameManager.h" @@ -487,9 +484,8 @@ nsXBLService::nsXBLService(void) #ifdef MOZ_XUL // Find out if the XUL cache is on or off - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) - prefBranch->GetBoolPref(kDisableChromeCachePref, &gDisableChromeCache); + gDisableChromeCache = nsContentUtils::GetBoolPref(kDisableChromeCachePref, + gDisableChromeCache); CallGetService("@mozilla.org/xul/xul-prototype-cache;1", &gXULCache); #endif diff --git a/mozilla/content/xml/content/src/nsXMLElement.cpp b/mozilla/content/xml/content/src/nsXMLElement.cpp index 769719b2268..ed317e7dbc5 100644 --- a/mozilla/content/xml/content/src/nsXMLElement.cpp +++ b/mozilla/content/xml/content/src/nsXMLElement.cpp @@ -62,8 +62,6 @@ #include "nsIPresShell.h" #include "nsGUIEvent.h" #include "nsIPresContext.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" #include "nsIDOMCSSStyleDeclaration.h" #include "nsIDOMViewCSS.h" #include "nsIXBLService.h" @@ -239,22 +237,13 @@ nsXMLElement::MaybeTriggerAutoLink(nsIDocShell *aShell) // XXX Should probably do this using atoms if (value.Equals(NS_LITERAL_STRING("new"))) { - nsCOMPtr prefBranch = - do_GetService(NS_PREFSERVICE_CONTRACTID); + if (nsContentUtils::GetBoolPref("dom.disable_open_during_load")) { + // disabling open during load - PRBool boolPref = PR_FALSE; - if (prefBranch) { - prefBranch->GetBoolPref("dom.disable_open_during_load", &boolPref); - if (boolPref) { - // disabling open during load - - return NS_OK; - } - - prefBranch->GetBoolPref("browser.block.target_new_window", - &boolPref); + return NS_OK; } - if (!boolPref) { + + if (!nsContentUtils::GetBoolPref("browser.block.target_new_window")) { // not blocking new windows verb = eLinkVerb_New; } @@ -347,15 +336,7 @@ nsXMLElement::HandleDOMEvent(nsIPresContext* aPresContext, // XXX Should probably do this using atoms if (show.Equals(NS_LITERAL_STRING("new"))) { - nsCOMPtr prefBranch = - do_GetService(NS_PREFSERVICE_CONTRACTID); - - PRBool blockNewWindow = PR_FALSE; - if (prefBranch) { - prefBranch->GetBoolPref("browser.block.target_new_window", - &blockNewWindow); - } - if (!blockNewWindow) { + if (!nsContentUtils::GetBoolPref("browser.block.target_new_window")) { verb = eLinkVerb_New; } } else if (show.Equals(NS_LITERAL_STRING("replace"))) { diff --git a/mozilla/content/xml/document/src/nsXMLContentSink.cpp b/mozilla/content/xml/document/src/nsXMLContentSink.cpp index 3f2ca80a412..d1efbce9eb0 100644 --- a/mozilla/content/xml/document/src/nsXMLContentSink.cpp +++ b/mozilla/content/xml/document/src/nsXMLContentSink.cpp @@ -398,10 +398,10 @@ nsXMLContentSink::SetParser(nsIParser* aParser) // static void -nsXMLContentSink::SplitXMLName(const nsAString& aString, nsIAtom **aPrefix, +nsXMLContentSink::SplitXMLName(const nsAFlatString& aString, nsIAtom **aPrefix, nsIAtom **aLocalName) { - nsReadingIterator iter, end; + nsAFlatString::const_iterator iter, end; aString.BeginReading(iter); aString.EndReading(end); diff --git a/mozilla/content/xml/document/src/nsXMLContentSink.h b/mozilla/content/xml/document/src/nsXMLContentSink.h index e92a78e85fd..80548444e7b 100644 --- a/mozilla/content/xml/document/src/nsXMLContentSink.h +++ b/mozilla/content/xml/document/src/nsXMLContentSink.h @@ -116,7 +116,7 @@ protected: nsresult AddContentAsLeaf(nsIContent *aContent); - static void SplitXMLName(const nsAString& aString, nsIAtom **aPrefix, + static void SplitXMLName(const nsAFlatString& aString, nsIAtom **aPrefix, nsIAtom **aTagName); PRInt32 GetNameSpaceId(nsIAtom* aPrefix); already_AddRefed PopNameSpaces(); diff --git a/mozilla/content/xml/document/src/nsXMLDocument.cpp b/mozilla/content/xml/document/src/nsXMLDocument.cpp index 10229058ad0..46db4df56eb 100644 --- a/mozilla/content/xml/document/src/nsXMLDocument.cpp +++ b/mozilla/content/xml/document/src/nsXMLDocument.cpp @@ -89,6 +89,7 @@ #include "nsIWindowWatcher.h" #include "nsIAuthPrompt.h" #include "nsIScriptGlobalObjectOwner.h" +#include "nsIJSContextStack.h" // XXX The XML world depends on the html atoms #include "nsHTMLAtoms.h" diff --git a/mozilla/content/xml/document/src/nsXMLPrettyPrinter.cpp b/mozilla/content/xml/document/src/nsXMLPrettyPrinter.cpp index 6a4030d456c..16e6471b827 100644 --- a/mozilla/content/xml/document/src/nsXMLPrettyPrinter.cpp +++ b/mozilla/content/xml/document/src/nsXMLPrettyPrinter.cpp @@ -37,11 +37,11 @@ * ***** END LICENSE BLOCK ***** */ #include "nsXMLPrettyPrinter.h" +#include "nsContentUtils.h" #include "nsIDOMDocumentView.h" #include "nsIDOMAbstractView.h" #include "nsIDOMCSSStyleDeclaration.h" #include "nsIDOMViewCSS.h" -#include "nsIPrefService.h" #include "nsIDOMDocumentXBL.h" #include "nsIBindingManager.h" #include "nsIObserver.h" @@ -114,17 +114,10 @@ nsXMLPrettyPrinter::PrettyPrint(nsIDocument* aDocument) } // check the pref - nsCOMPtr prefBranch = - do_GetService(NS_PREFSERVICE_CONTRACTID); - if (prefBranch) { - PRBool pref = PR_TRUE; - prefBranch->GetBoolPref("layout.xml.prettyprint", &pref); - if (!pref) { - return NS_OK; - } + if (!nsContentUtils::GetBoolPref("layout.xml.prettyprint", PR_TRUE)) { + return NS_OK; } - // Ok, we should prettyprint. Let's do it! nsresult rv = NS_OK; diff --git a/mozilla/content/xul/content/src/Makefile.in b/mozilla/content/xul/content/src/Makefile.in index 1d249565f2b..f1d5a68cd89 100644 --- a/mozilla/content/xul/content/src/Makefile.in +++ b/mozilla/content/xul/content/src/Makefile.in @@ -57,6 +57,7 @@ REQUIRES = xpcom \ caps \ rdf \ xpconnect \ + pref \ locale \ lwbrk \ xuldoc \ diff --git a/mozilla/content/xul/content/src/nsXULPopupListener.cpp b/mozilla/content/xul/content/src/nsXULPopupListener.cpp index 36cadb888aa..0a7a8806e19 100644 --- a/mozilla/content/xul/content/src/nsXULPopupListener.cpp +++ b/mozilla/content/xul/content/src/nsXULPopupListener.cpp @@ -67,8 +67,6 @@ #include "nsIDOMNSUIEvent.h" #include "nsIDOMEventTarget.h" #include "nsIDOMNSEvent.h" -#include "nsIPrefService.h" -#include "nsIPrefBranch.h" #include "nsIServiceManagerUtils.h" #include "nsIPrincipal.h" #include "nsIScriptSecurityManager.h" @@ -233,18 +231,9 @@ XULPopupListenerImpl::PreLaunchPopup(nsIDOMEvent* aMouseEvent) if (preventDefault && targetNode && popupType == eXULPopupType_context) { // Someone called preventDefault on a context menu. // Let's make sure they are allowed to do so. - nsCOMPtr prefService = - do_GetService(NS_PREFSERVICE_CONTRACTID); - - NS_ENSURE_TRUE(prefService, NS_ERROR_FAILURE); - - nsCOMPtr prefBranch; - prefService->GetBranch(nsnull, getter_AddRefs(prefBranch)); - - PRBool eventEnabled; - nsresult rv = prefBranch->GetBoolPref("dom.event.contextmenu.enabled", - &eventEnabled); - if (NS_SUCCEEDED(rv) && !eventEnabled) { + PRBool eventEnabled = + nsContentUtils::GetBoolPref("dom.event.contextmenu.enabled", PR_TRUE); + if (!eventEnabled) { // The user wants his contextmenus. Let's make sure that this is a website // and not chrome since there could be places in chrome which don't want // contextmenus. diff --git a/mozilla/content/xul/document/src/nsXULPrototypeCache.cpp b/mozilla/content/xul/document/src/nsXULPrototypeCache.cpp index bdc48ae3343..e84561280dc 100644 --- a/mozilla/content/xul/document/src/nsXULPrototypeCache.cpp +++ b/mozilla/content/xul/document/src/nsXULPrototypeCache.cpp @@ -41,6 +41,7 @@ #include "nsCOMPtr.h" #include "nsXPIDLString.h" +#include "nsContentUtils.h" #include "nsICSSStyleSheet.h" #include "nsIXULPrototypeCache.h" #include "nsIXULPrototypeDocument.h" @@ -51,7 +52,6 @@ #include "plstr.h" #include "nsIDocument.h" #include "nsIXBLDocumentInfo.h" -#include "nsIPref.h" #include "nsIServiceManager.h" #include "nsXULDocument.h" #include "nsIJSRuntimeService.h" @@ -144,9 +144,8 @@ static const char kDisableXULCachePref[] = "nglayout.debug.disable_xul_cache"; PR_STATIC_CALLBACK(int) DisableXULCacheChangedCallback(const char* aPref, void* aClosure) { - nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID); - if (prefs) - prefs->GetBoolPref(kDisableXULCachePref, &gDisableXULCache); + gDisableXULCache = + nsContentUtils::GetBoolPref(kDisableXULCachePref, gDisableXULCache); // Flush the cache, regardless static NS_DEFINE_CID(kXULPrototypeCacheCID, NS_XULPROTOTYPECACHE_CID); @@ -191,39 +190,34 @@ NS_NewXULPrototypeCache(nsISupports* aOuter, REFNSIID aIID, void** aResult) if (aOuter) return NS_ERROR_NO_AGGREGATION; - nsXULPrototypeCache* result = new nsXULPrototypeCache(); + nsRefPtr result = new nsXULPrototypeCache(); if (! result) return NS_ERROR_OUT_OF_MEMORY; - nsresult rv; - if (!(result->mPrototypeTable.Init() && result->mStyleSheetTable.Init() && result->mScriptTable.Init() && result->mXBLDocTable.Init() && result->mFastLoadURITable.Init())) { - delete result; return NS_ERROR_OUT_OF_MEMORY; } - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (NS_SUCCEEDED(rv)) { - // XXX Ignore return values. - prefs->GetBoolPref(kDisableXULCachePref, &gDisableXULCache); - prefs->RegisterCallback(kDisableXULCachePref, DisableXULCacheChangedCallback, nsnull); - } + // XXX Ignore return values. + gDisableXULCache = + nsContentUtils::GetBoolPref(kDisableXULCachePref, gDisableXULCache); + nsContentUtils::RegisterPrefCallback(kDisableXULCachePref, + DisableXULCacheChangedCallback, + nsnull); - NS_ADDREF(result); - rv = result->QueryInterface(aIID, aResult); + nsresult rv = result->QueryInterface(aIID, aResult); nsCOMPtr obsSvc(do_GetService("@mozilla.org/observer-service;1")); if (obsSvc && NS_SUCCEEDED(rv)) { - obsSvc->AddObserver(result, "chrome-flush-skin-caches", PR_FALSE); - obsSvc->AddObserver(result, "chrome-flush-caches", PR_FALSE); + nsXULPrototypeCache *p = result; + obsSvc->AddObserver(p, "chrome-flush-skin-caches", PR_FALSE); + obsSvc->AddObserver(p, "chrome-flush-caches", PR_FALSE); } - NS_RELEASE(result); - return rv; } @@ -689,20 +683,24 @@ nsXULPrototypeCache::StartFastLoadingURI(nsIURI* aURI, PRInt32 aDirectionFlags) PR_STATIC_CALLBACK(int) FastLoadPrefChangedCallback(const char* aPref, void* aClosure) { - nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID); - if (prefs) { - PRBool wasEnabled = !gDisableXULFastLoad; - prefs->GetBoolPref(kDisableXULFastLoadPref, &gDisableXULFastLoad); + PRBool wasEnabled = !gDisableXULFastLoad; + gDisableXULFastLoad = + nsContentUtils::GetBoolPref(kDisableXULFastLoadPref, + gDisableXULFastLoad); - if (wasEnabled && gDisableXULFastLoad) { - static NS_DEFINE_CID(kXULPrototypeCacheCID, NS_XULPROTOTYPECACHE_CID); - nsCOMPtr cache(do_GetService(kXULPrototypeCacheCID)); - if (cache) - cache->AbortFastLoads(); - } + if (wasEnabled && gDisableXULFastLoad) { + static NS_DEFINE_CID(kXULPrototypeCacheCID, NS_XULPROTOTYPECACHE_CID); + nsCOMPtr cache = + do_GetService(kXULPrototypeCacheCID); - prefs->GetBoolPref(kChecksumXULFastLoadFilePref, &gChecksumXULFastLoadFile); + if (cache) + cache->AbortFastLoads(); } + + gChecksumXULFastLoadFile = + nsContentUtils::GetBoolPref(kChecksumXULFastLoadFilePref, + gChecksumXULFastLoadFile); + return 0; } @@ -810,20 +808,21 @@ nsXULPrototypeCache::StartFastLoad(nsIURI* aURI) if (! fastLoadService) return NS_ERROR_FAILURE; - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID)); - if (prefs) { - prefs->GetBoolPref(kDisableXULFastLoadPref, &gDisableXULFastLoad); - prefs->GetBoolPref(kChecksumXULFastLoadFilePref, &gChecksumXULFastLoadFile); - prefs->RegisterCallback(kDisableXULFastLoadPref, - FastLoadPrefChangedCallback, - nsnull); - prefs->RegisterCallback(kChecksumXULFastLoadFilePref, - FastLoadPrefChangedCallback, - nsnull); + gDisableXULFastLoad = + nsContentUtils::GetBoolPref(kDisableXULFastLoadPref, + gDisableXULFastLoad); + gChecksumXULFastLoadFile = + nsContentUtils::GetBoolPref(kChecksumXULFastLoadFilePref, + gChecksumXULFastLoadFile); + nsContentUtils::RegisterPrefCallback(kDisableXULFastLoadPref, + FastLoadPrefChangedCallback, + nsnull); + nsContentUtils::RegisterPrefCallback(kChecksumXULFastLoadFilePref, + FastLoadPrefChangedCallback, + nsnull); - if (gDisableXULFastLoad) - return NS_ERROR_NOT_AVAILABLE; - } + if (gDisableXULFastLoad) + return NS_ERROR_NOT_AVAILABLE; // Get the chrome directory to validate against the one stored in the // FastLoad file, or to store there if we're generating a new file. diff --git a/mozilla/content/xul/templates/src/Makefile.in b/mozilla/content/xul/templates/src/Makefile.in index 52568b0acf4..4cd74c486d2 100644 --- a/mozilla/content/xul/templates/src/Makefile.in +++ b/mozilla/content/xul/templates/src/Makefile.in @@ -53,6 +53,7 @@ REQUIRES = xpcom \ htmlparser \ layout \ content \ + pref \ widget \ dom \ rdf \ diff --git a/mozilla/dom/src/base/nsGlobalWindow.cpp b/mozilla/dom/src/base/nsGlobalWindow.cpp index 1e46d8b6a0a..877696c3951 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -98,9 +98,7 @@ #include "nsIJSContextStack.h" #include "nsIJSRuntimeService.h" #include "nsIMarkupDocumentViewer.h" -#include "nsIPrefService.h" #include "nsIPrefBranch.h" -#include "nsIPrefLocalizedString.h" #include "nsIPresShell.h" #include "nsIPrivateDOMEvent.h" #include "nsIProgrammingLanguage.h" @@ -136,6 +134,7 @@ #include "nsIControllerContext.h" #include "nsGlobalWindowCommands.h" #include "nsAutoPtr.h" +#include "nsContentUtils.h" #include "plbase64.h" @@ -156,7 +155,6 @@ #include "nsIPopupWindowManager.h" static nsIEntropyCollector *gEntropyCollector = nsnull; -static nsIPrefBranch *gPrefBranch = nsnull; static PRInt32 gRefCnt = 0; static PRInt32 gOpenPopupSpamCount = 0; nsIXPConnect *GlobalWindowImpl::sXPConnect = nsnull; @@ -237,6 +235,7 @@ GlobalWindowImpl::GlobalWindowImpl() mRunningTimeout(nsnull), mTimeoutPublicIdCounter(1), mTimeoutFiringDepth(0), + mMutationBits(0), mFirstDocumentLoad(PR_TRUE), mIsScopeClear(PR_TRUE), mIsDocumentLoaded(PR_FALSE), @@ -248,7 +247,6 @@ GlobalWindowImpl::GlobalWindowImpl() mGlobalObjectOwner(nsnull), mDocShell(nsnull), mCurrentEvent(0), - mMutationBits(0), mChromeEventHandler(nsnull), mFrameElement(nsnull) { @@ -262,10 +260,6 @@ GlobalWindowImpl::GlobalWindowImpl() printf("++DOMWINDOW == %d\n", gRefCnt); #endif - if (!gPrefBranch) { - CallGetService(NS_PREFSERVICE_CONTRACTID, &gPrefBranch); - } - if (!sXPConnect) { CallGetService(nsIXPConnect::GetCID(), &sXPConnect); } @@ -287,12 +281,6 @@ GlobalWindowImpl::~GlobalWindowImpl() mDocument = nsnull; // Forces Release CleanUp(); - - if (!gRefCnt) { - // Destroy the Pref Branch last, since some things need - // to use it before it goes away. - NS_IF_RELEASE(gPrefBranch); - } } // static @@ -2119,17 +2107,11 @@ GlobalWindowImpl::Dump(const nsAString& aStr) // enable output from dump() or not, in debug builds it's always // enabled. - if (!gPrefBranch) { - return NS_OK; - } - - PRBool enable_dump = PR_FALSE; - // if pref doesn't exist, disable dump output. - nsresult rv = gPrefBranch->GetBoolPref("browser.dom.window.dump.enabled", - &enable_dump); + PRBool enable_dump = + nsContentUtils::GetBoolPref("browser.dom.window.dump.enabled"); - if (NS_FAILED(rv) || !enable_dump) { + if (!enable_dump) { return NS_OK; } } @@ -2563,24 +2545,15 @@ GlobalWindowImpl::Home() if (!mDocShell) return NS_OK; - NS_ENSURE_STATE(gPrefBranch); + nsAdoptingString homeURL = + nsContentUtils::GetLocalizedStringPref(PREF_BROWSER_STARTUP_HOMEPAGE); - nsCOMPtr url; - gPrefBranch->GetComplexValue(PREF_BROWSER_STARTUP_HOMEPAGE, - NS_GET_IID(nsIPrefLocalizedString), - getter_AddRefs(url)); - nsString homeURL; - if (url) { - nsXPIDLString tmp; - url->GetData(getter_Copies(tmp)); - homeURL = tmp; - } - else { + if (homeURL.IsEmpty()) { // if all else fails, use this #ifdef DEBUG_seth printf("all else failed. using %s as the home page\n", DEFAULT_HOME_PAGE); #endif - homeURL.AssignWithConversion(DEFAULT_HOME_PAGE); + CopyASCIItoUTF16(DEFAULT_HOME_PAGE, homeURL); } nsresult rv; @@ -2979,10 +2952,8 @@ void FirePopupWindowEvent(nsIDOMDocument* aDoc) PRBool GlobalWindowImpl::CanSetProperty(const char *aPrefName) { - NS_ENSURE_STATE(gPrefBranch); - - PRBool prefValue = PR_TRUE; - gPrefBranch->GetBoolPref(aPrefName, &prefValue); + PRBool prefValue = + nsContentUtils::GetBoolPref(aPrefName, PR_TRUE); // If the pref is set to true, we can not set the property // and vice versa. @@ -3009,15 +2980,12 @@ GlobalWindowImpl::CheckForAbusePoint() return openAllowed; } - if (!gPrefBranch) - return openAllowed; - PRUint32 abuse = openAllowed; // level of abuse we've detected - PRInt32 intPref = 0; - // disallow windows after a user-defined click delay - gPrefBranch->GetIntPref("dom.disable_open_click_delay", &intPref); + PRInt32 intPref = + nsContentUtils::GetIntPref("dom.disable_open_click_delay"); + if (intPref != 0) { PRTime now = PR_Now(); PRTime ll_delta; @@ -3054,10 +3022,8 @@ GlobalWindowImpl::CheckForAbusePoint() } // fetch pref string detailing which events are allowed - nsXPIDLCString eventPref; - gPrefBranch->GetCharPref("dom.popup_allowed_events", - getter_Copies(eventPref)); - nsCAutoString eventPrefStr(eventPref); + const nsAdoptingCString& eventPref = + nsContentUtils::GetCharPref("dom.popup_allowed_events"); // generally if an event handler is running, new windows are disallowed. // check for exceptions: @@ -3170,9 +3136,9 @@ GlobalWindowImpl::CheckForAbusePoint() // limit the number of simultaneously open popups if (abuse == openAbused || abuse == openControlled) { - intPref = 0; - nsresult gotPref = gPrefBranch->GetIntPref("dom.popup_maximum", &intPref); - if (NS_SUCCEEDED(gotPref) && intPref >= 0 && gOpenPopupSpamCount >= intPref) + intPref = nsContentUtils::GetIntPref("dom.popup_maximum", -1); + + if (intPref >= 0 && gOpenPopupSpamCount >= intPref) abuse = openOverridden; } @@ -3539,9 +3505,9 @@ GlobalWindowImpl::Close() PRBool inChrome = PR_TRUE; rv = secMan->SubjectPrincipalIsSystem(&inChrome); if (NS_SUCCEEDED(rv) && !inChrome) { - PRBool allowClose = PR_TRUE; - gPrefBranch->GetBoolPref("dom.allow_scripts_to_close_windows", - &allowClose); + PRBool allowClose = + nsContentUtils::GetBoolPref("dom.allow_scripts_to_close_windows", + PR_TRUE); if (!allowClose) { // We're blocking the close operation // report localized error msg in JS console @@ -6186,22 +6152,12 @@ NavigatorImpl::GetPlugins(nsIDOMPluginArray **aPlugins) NS_IMETHODIMP NavigatorImpl::GetCookieEnabled(PRBool *aCookieEnabled) { - *aCookieEnabled = PR_FALSE; + *aCookieEnabled = + (nsContentUtils::GetIntPref("network.cookie.cookieBehavior", + COOKIE_BEHAVIOR_REJECT) != + COOKIE_BEHAVIOR_REJECT); - nsCOMPtr prefBranch(gPrefBranch); - if (!prefBranch) { - prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); - NS_ENSURE_STATE(prefBranch); - } - - PRInt32 cookieBehaviorPref; - nsresult rv = prefBranch->GetIntPref("network.cookie.cookieBehavior", - &cookieBehaviorPref); - if (NS_SUCCEEDED(rv)) { - *aCookieEnabled = cookieBehaviorPref != COOKIE_BEHAVIOR_REJECT; - } - - return rv; + return NS_OK; } NS_IMETHODIMP @@ -6228,17 +6184,8 @@ NavigatorImpl::JavaEnabled(PRBool *aReturn) #ifdef OJI // determine whether user has enabled java. - nsCOMPtr prefBranch(gPrefBranch); - if (!prefBranch) { - prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); - NS_ENSURE_STATE(prefBranch); - } - // if pref doesn't exist, map result to false. - if (NS_FAILED(prefBranch->GetBoolPref("security.enable_java", aReturn))) { - *aReturn = PR_FALSE; - return NS_OK; - } + *aReturn = nsContentUtils::GetBoolPref("security.enable_java"); // if Java is not enabled, result is false and return reight away if (!*aReturn) @@ -6324,11 +6271,8 @@ NavigatorImpl::Preference() return NS_OK; } - nsCOMPtr prefBranch(gPrefBranch); - if (!prefBranch) { - prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); - NS_ENSURE_STATE(prefBranch); - } + nsIPrefBranch *prefBranch = nsContentUtils::GetPrefBranch(); + NS_ENSURE_STATE(prefBranch); JSString *str = ::JS_ValueToString(cx, argv[0]); NS_ENSURE_TRUE(str, NS_ERROR_OUT_OF_MEMORY); diff --git a/mozilla/dom/src/base/nsGlobalWindow.h b/mozilla/dom/src/base/nsGlobalWindow.h index b4e79a19ffe..f83ec7fb05a 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.h +++ b/mozilla/dom/src/base/nsGlobalWindow.h @@ -302,6 +302,7 @@ protected: nsTimeoutImpl* mRunningTimeout; PRUint32 mTimeoutPublicIdCounter; PRUint32 mTimeoutFiringDepth; + PRUint32 mMutationBits; PRPackedBool mFirstDocumentLoad; PRPackedBool mIsScopeClear; PRPackedBool mIsDocumentLoaded; // true between onload and onunload events @@ -316,7 +317,6 @@ protected: nsIScriptGlobalObjectOwner* mGlobalObjectOwner; // Weak Reference nsIDocShell* mDocShell; // Weak Reference nsEvent* mCurrentEvent; - PRUint32 mMutationBits; nsCOMPtr mChromeEventHandler; // [Strong] We break it when we get torn down. nsCOMPtr mCrypto; nsCOMPtr mPkcs11; @@ -370,7 +370,7 @@ struct nsTimeoutImpl { #ifdef DEBUG_jst { - extern gTimeoutCnt; + extern int gTimeoutCnt; ++gTimeoutCnt; } @@ -385,7 +385,7 @@ struct nsTimeoutImpl { #ifdef DEBUG_jst { - extern gTimeoutCnt; + extern int gTimeoutCnt; --gTimeoutCnt; } diff --git a/mozilla/dom/src/base/nsGlobalWindowCommands.cpp b/mozilla/dom/src/base/nsGlobalWindowCommands.cpp index a251787020c..589308fb942 100644 --- a/mozilla/dom/src/base/nsGlobalWindowCommands.cpp +++ b/mozilla/dom/src/base/nsGlobalWindowCommands.cpp @@ -261,7 +261,7 @@ nsSelectMoveScrollCommand::DoSelectCommand(const char *aCommandName, nsIDOMWindo nsCOMPtr esm; GetEventStateManagerForWindow(aWindow, getter_AddRefs(esm)); if (esm) - esm->GetBrowseWithCaret(&doBrowseWithCaret); + doBrowseWithCaret = esm->GetBrowseWithCaret(); nsresult rv; if (doBrowseWithCaret) diff --git a/mozilla/dom/src/base/nsJSEnvironment.cpp b/mozilla/dom/src/base/nsJSEnvironment.cpp index 9ad5b3cb0f2..08a718c3b15 100644 --- a/mozilla/dom/src/base/nsJSEnvironment.cpp +++ b/mozilla/dom/src/base/nsJSEnvironment.cpp @@ -57,7 +57,6 @@ #include "nsIXPConnect.h" #include "nsIJSContextStack.h" #include "nsIJSRuntimeService.h" -#include "nsIPref.h" #include "nsCOMPtr.h" #include "nsReadableUtils.h" #include "nsJSUtils.h" @@ -76,8 +75,7 @@ #include "nsITimer.h" #include "nsDOMClassInfo.h" #include "nsIAtom.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" +#include "nsContentUtils.h" // For locale aware string methods #include "nsUnicharUtils.h" @@ -482,38 +480,30 @@ static const char js_werror_option_str[] = JS_OPTIONS_DOT_STR "werror"; int PR_CALLBACK nsJSContext::JSOptionChangedCallback(const char *pref, void *data) { - nsresult rv; - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (NS_SUCCEEDED(rv)) { - nsJSContext *context = NS_REINTERPRET_CAST(nsJSContext *, data); - PRUint32 oldDefaultJSOptions = context->mDefaultJSOptions; - PRUint32 newDefaultJSOptions = oldDefaultJSOptions; + nsJSContext *context = NS_REINTERPRET_CAST(nsJSContext *, data); + PRUint32 oldDefaultJSOptions = context->mDefaultJSOptions; + PRUint32 newDefaultJSOptions = oldDefaultJSOptions; - PRBool strict; - if (NS_SUCCEEDED(prefs->GetBoolPref(js_strict_option_str, &strict))) { - if (strict) - newDefaultJSOptions |= JSOPTION_STRICT; - else - newDefaultJSOptions &= ~JSOPTION_STRICT; - } + PRBool strict = nsContentUtils::GetBoolPref(js_strict_option_str); + if (strict) + newDefaultJSOptions |= JSOPTION_STRICT; + else + newDefaultJSOptions &= ~JSOPTION_STRICT; - PRBool werror; - if (NS_SUCCEEDED(prefs->GetBoolPref(js_werror_option_str, &werror))) { - if (werror) - newDefaultJSOptions |= JSOPTION_WERROR; - else - newDefaultJSOptions &= ~JSOPTION_WERROR; - } + PRBool werror = nsContentUtils::GetBoolPref(js_werror_option_str); + if (werror) + newDefaultJSOptions |= JSOPTION_WERROR; + else + newDefaultJSOptions &= ~JSOPTION_WERROR; - if (newDefaultJSOptions != oldDefaultJSOptions) { - // Set options only if we used the old defaults; otherwise the page has - // customized some via the options object and we defer to its wisdom. - if (::JS_GetOptions(context->mContext) == oldDefaultJSOptions) - ::JS_SetOptions(context->mContext, newDefaultJSOptions); + if (newDefaultJSOptions != oldDefaultJSOptions) { + // Set options only if we used the old defaults; otherwise the page has + // customized some via the options object and we defer to its wisdom. + if (::JS_GetOptions(context->mContext) == oldDefaultJSOptions) + ::JS_SetOptions(context->mContext, newDefaultJSOptions); - // Save the new defaults for the next page load (InitContext). - context->mDefaultJSOptions = newDefaultJSOptions; - } + // Save the new defaults for the next page load (InitContext). + context->mDefaultJSOptions = newDefaultJSOptions; } return 0; } @@ -573,12 +563,10 @@ nsJSContext::nsJSContext(JSRuntime *aRuntime) : mGCOnDestruction(PR_TRUE) ::JS_SetOptions(mContext, mDefaultJSOptions); // Check for the JS strict option, which enables extra error checks - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (NS_SUCCEEDED(rv)) { - prefs->RegisterCallback(js_options_dot_str, JSOptionChangedCallback, - this); - JSOptionChangedCallback(js_options_dot_str, this); - } + nsContentUtils::RegisterPrefCallback(js_options_dot_str, + JSOptionChangedCallback, + this); + JSOptionChangedCallback(js_options_dot_str, this); ::JS_SetBranchCallback(mContext, DOMBranchCallback); @@ -616,11 +604,9 @@ nsJSContext::~nsJSContext() ::JS_SetBranchCallback(mContext, nsnull); // Unregister our "javascript.options.*" pref-changed callback. - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID)); - if (prefs) { - prefs->UnregisterCallback(js_options_dot_str, JSOptionChangedCallback, - this); - } + nsContentUtils::UnregisterPrefCallback(js_options_dot_str, + JSOptionChangedCallback, + this); // Release mGlobalWrapperRef before the context is destroyed mGlobalWrapperRef = nsnull; @@ -1939,16 +1925,11 @@ nsJSEnvironment::Init() // Initialize limit on script run time to 5 seconds PRInt32 maxtime = 5; - nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); - if (prefs) { - PRInt32 time; - if (NS_SUCCEEDED(prefs->GetIntPref("dom.max_script_run_time", &time))) { + PRInt32 time = nsContentUtils::GetIntPref("dom.max_script_run_time"); - // Force the default for unreasonable values - if (time > 0) - maxtime = time; - } - } + // Force the default for unreasonable values + if (time > 0) + maxtime = time; PRTime usec_per_sec; LL_I2L(usec_per_sec, PR_USEC_PER_SEC); diff --git a/mozilla/layout/base/nsCSSFrameConstructor.cpp b/mozilla/layout/base/nsCSSFrameConstructor.cpp index 57b8fd39242..c090826d615 100644 --- a/mozilla/layout/base/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/base/nsCSSFrameConstructor.cpp @@ -91,8 +91,6 @@ #include "nsISupportsArray.h" #include "nsIAnonymousContentCreator.h" #include "nsFrameManager.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" #include "nsLegendFrame.h" #include "nsIContentIterator.h" #include "nsBoxLayoutState.h" @@ -101,6 +99,7 @@ #include "nsIElementFactory.h" #include "nsITheme.h" #include "nsContentCID.h" +#include "nsContentUtils.h" #include "nsIDocShell.h" #include "nsFormControlHelper.h" #include "nsObjectFrame.h" @@ -1265,12 +1264,8 @@ nsCSSFrameConstructor::nsCSSFrameConstructor(nsIDocument *aDocument) if (!gGotXBLFormPrefs) { gGotXBLFormPrefs = PR_TRUE; - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - prefBranch->GetBoolPref("nglayout.debug.enable_xbl_forms", - &gUseXBLForms); - - } + gUseXBLForms = + nsContentUtils::GetBoolPref("nglayout.debug.enable_xbl_forms"); } #ifdef DEBUG @@ -12513,7 +12508,7 @@ nsCSSFrameConstructor::ConstructBlock(nsIPresShell* aPresShell, // ...and that we're the absolute containing block. nsFrameConstructorSaveState absoluteSaveState; if (aRelPos || !aState.mAbsoluteItems.containingBlock) { - NS_ASSERTION(aRelPos, "should have made area frame for this"); + // NS_ASSERTION(aRelPos, "should have made area frame for this"); aState.PushAbsoluteContainingBlock(aPresContext, aNewFrame, absoluteSaveState); } diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index d5bc8eb39fe..c87abfa35be 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -81,9 +81,6 @@ #include "nsIViewManager.h" #include "nsIView.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" -#include "nsIPrefLocalizedString.h" #include "nsIPageSequenceFrame.h" #include "nsIURL.h" #include "nsNetUtil.h" @@ -2348,7 +2345,8 @@ SetChildTextZoom(nsIMarkupDocumentViewer* aChild, void* aClosure) aChild->SetTextZoom(textZoomInfo->mTextZoom); } -NS_IMETHODIMP DocumentViewerImpl::SetTextZoom(float aTextZoom) +NS_IMETHODIMP +DocumentViewerImpl::SetTextZoom(float aTextZoom) { if (mDeviceContext) { float oldTextZoom = 1.0; // just in case mDeviceContext doesn't implement @@ -2367,7 +2365,8 @@ NS_IMETHODIMP DocumentViewerImpl::SetTextZoom(float aTextZoom) return CallChildren(SetChildTextZoom, &textZoomInfo); } -NS_IMETHODIMP DocumentViewerImpl::GetTextZoom(float* aTextZoom) +NS_IMETHODIMP +DocumentViewerImpl::GetTextZoom(float* aTextZoom) { NS_ENSURE_ARG_POINTER(aTextZoom); @@ -2379,35 +2378,18 @@ NS_IMETHODIMP DocumentViewerImpl::GetTextZoom(float* aTextZoom) return NS_OK; } -// XXX: SEMANTIC CHANGE! -// returns a copy of the string. Caller is responsible for freeing result -// using Recycle(aDefaultCharacterSet) -NS_IMETHODIMP DocumentViewerImpl::GetDefaultCharacterSet(nsACString& aDefaultCharacterSet) +NS_IMETHODIMP +DocumentViewerImpl::GetDefaultCharacterSet(nsACString& aDefaultCharacterSet) { NS_ENSURE_STATE(mContainer); if (mDefaultCharacterSet.IsEmpty()) { - nsXPIDLString defCharset; - - nsCOMPtr webShell; - webShell = do_QueryInterface(mContainer); - if (webShell) - { - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - nsCOMPtr prefLocalString; - prefBranch->GetComplexValue("intl.charset.default", - NS_GET_IID(nsIPrefLocalizedString), - getter_AddRefs(prefLocalString)); - if (prefLocalString) { - prefLocalString->GetData(getter_Copies(defCharset)); - } - } - } + const nsAdoptingString& defCharset = + nsContentUtils::GetLocalizedStringPref("intl.charset.default"); if (!defCharset.IsEmpty()) - CopyUCS2toASCII(defCharset, mDefaultCharacterSet); + LossyCopyUTF16toASCII(defCharset, mDefaultCharacterSet); else mDefaultCharacterSet.Assign(NS_LITERAL_CSTRING("ISO-8859-1")); } diff --git a/mozilla/layout/base/nsPresContext.cpp b/mozilla/layout/base/nsPresContext.cpp index 19c7a25be1b..475f6d72921 100644 --- a/mozilla/layout/base/nsPresContext.cpp +++ b/mozilla/layout/base/nsPresContext.cpp @@ -37,7 +37,6 @@ #include "nsCOMPtr.h" #include "nsPresContext.h" #include "nsIPresShell.h" -#include "nsIPref.h" #include "nsILinkHandler.h" #include "nsIDocShellTreeItem.h" #include "nsStyleSet.h" @@ -73,6 +72,8 @@ #include "nsBidiPresUtils.h" #endif // IBMBIDI +#include "nsContentUtils.h" + // Needed for Start/Stop of Image Animation #include "imgIContainer.h" #include "nsIImageLoadingContent.h" @@ -134,6 +135,8 @@ static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); #include "nsContentCID.h" static NS_DEFINE_CID(kSelectionImageService, NS_SELECTIONIMAGESERVICE_CID); + // NOTE! nsPresContext::operator new() zeroes out all members, so don't + // bother initializing members to 0. nsPresContext::nsPresContext() : mDefaultVariableFont("serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, @@ -151,6 +154,10 @@ nsPresContext::nsPresContext() mDefaultFantasyFont("fantasy", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)) { + + // NOTE! nsPresContext::operator new() zeroes out all members, so don't + // bother initializing members to 0. + mCompatibilityMode = eCompatibility_FullStandards; mImageAnimationMode = imgIContainer::kNormalAnimMode; mImageAnimationModePref = imgIContainer::kNormalAnimMode; @@ -158,40 +165,25 @@ nsPresContext::nsPresContext() SetBackgroundImageDraw(PR_TRUE); // always draw the background SetBackgroundColorDraw(PR_TRUE); - mShell = nsnull; - mLinkHandler = nsnull; - mContainer = nsnull; - mViewportStyleOverflow = NS_STYLE_OVERFLOW_AUTO; - mDefaultColor = NS_RGB(0x00, 0x00, 0x00); mBackgroundColor = NS_RGB(0xFF, 0xFF, 0xFF); mUseDocumentColors = PR_TRUE; mUseDocumentFonts = PR_TRUE; // the minimum font-size is unconstrained by default - mMinimumFontSize = 0; mLinkColor = NS_RGB(0x00, 0x00, 0xEE); mActiveLinkColor = NS_RGB(0xEE, 0x00, 0x00); mVisitedLinkColor = NS_RGB(0x55, 0x1A, 0x8B); mUnderlineLinks = PR_TRUE; - mUseFocusColors = PR_FALSE; mFocusTextColor = mDefaultColor; mFocusBackgroundColor = mBackgroundColor; mFocusRingWidth = 1; - mFocusRingOnAnything = PR_FALSE; mLanguageSpecificTransformType = eLanguageSpecificTransformType_Unknown; - mIsRenderingOnlySelection = PR_FALSE; -#ifdef IBMBIDI - mIsVisual = PR_FALSE; - mBidiUtils = nsnull; - mIsBidiSystem = PR_FALSE; - mBidi = 0; -#endif // IBMBIDI } nsPresContext::~nsPresContext() @@ -207,23 +199,34 @@ nsPresContext::~nsPresContext() } // 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.active_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); + nsContentUtils::UnregisterPrefCallback("font.", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::UnregisterPrefCallback("browser.display.", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::UnregisterPrefCallback("browser.underline_anchors", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::UnregisterPrefCallback("browser.anchor_color", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::UnregisterPrefCallback("browser.active_color", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::UnregisterPrefCallback("browser.visited_color", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::UnregisterPrefCallback("network.image.imageBehavior", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::UnregisterPrefCallback("image.animation_mode", + nsPresContext::PrefChangedCallback, + this); #ifdef IBMBIDI - mPrefs->UnregisterCallback("bidi.", PrefChangedCallback, (void*)this); -#endif - } -#ifdef IBMBIDI - if (mBidiUtils) { - delete mBidiUtils; - } + nsContentUtils::UnregisterPrefCallback("bidi.", PrefChangedCallback, this); + + delete mBidiUtils; #endif // IBMBIDI NS_IF_RELEASE(mDeviceContext); @@ -250,7 +253,7 @@ static const char* const kGenericFont[] = { void nsPresContext::GetFontPreferences() { - if (!mPrefs || !mLanguage) + if (!mLanguage) return; /* Fetch the font prefs to be used -- see bug 61883 for details. @@ -280,18 +283,19 @@ nsPresContext::GetFontPreferences() langGroupAtom->ToString(langGroup); nsCAutoString pref; - nsXPIDLString value; - nsXPIDLCString cvalue; // get the current applicable font-size unit enum {eUnit_unknown = -1, eUnit_px, eUnit_pt}; PRInt32 unit = eUnit_px; - nsresult rv = mPrefs->CopyCharPref("font.size.unit", getter_Copies(cvalue)); - if (NS_SUCCEEDED(rv)) { - if (!PL_strcmp(cvalue.get(), "px")) { + + nsAdoptingCString cvalue = + nsContentUtils::GetCharPref("font.size.unit"); + + if (!cvalue.IsEmpty()) { + if (cvalue.Equals("px")) { unit = eUnit_px; } - else if (!PL_strcmp(cvalue.get(), "pt")) { + else if (cvalue.Equals("pt")) { unit = eUnit_pt; } else { @@ -301,13 +305,12 @@ nsPresContext::GetFontPreferences() } // get font.minimum-size.[langGroup] - PRInt32 size; pref.Assign("font.minimum-size."); AppendUTF16toUTF8(langGroup, pref); - rv = mPrefs->GetIntPref(pref.get(), &size); - if (NS_SUCCEEDED(rv)) { + PRInt32 size = nsContentUtils::GetIntPref(pref.get()); + if (size > 0) { if (unit == eUnit_px) { mMinimumFontSize = NSFloatPixelsToTwips((float)size, p2t); } @@ -338,13 +341,15 @@ nsPresContext::GetFontPreferences() // in GFX and will be queried there when hunting for alternative fonts) if (eType == eDefaultFont_Variable) { MAKE_FONT_PREF_KEY(pref, "font.name", generic_dot_langGroup); - rv = mPrefs->CopyUnicharPref(pref.get(), getter_Copies(value)); - if (NS_SUCCEEDED(rv)) { + + nsAdoptingString value = + nsContentUtils::GetStringPref(pref.get()); + if (!value.IsEmpty()) { font->name.Assign(value); } else { - rv = mPrefs->CopyUnicharPref("font.default", getter_Copies(value)); - if (NS_SUCCEEDED(rv)) { + value = nsContentUtils::GetStringPref("font.default"); + if (!value.IsEmpty()) { mDefaultVariableFont.name.Assign(value); } } @@ -372,8 +377,8 @@ nsPresContext::GetFontPreferences() // get font.size.[generic].[langGroup] // size=0 means 'Auto', i.e., generic fonts retain the size of the variable font MAKE_FONT_PREF_KEY(pref, "font.size", generic_dot_langGroup); - rv = mPrefs->GetIntPref(pref.get(), &size); - if (NS_SUCCEEDED(rv) && size > 0) { + size = nsContentUtils::GetIntPref(pref.get()); + if (size > 0) { if (unit == eUnit_px) { font->size = NSFloatPixelsToTwips((float)size, p2t); } @@ -385,14 +390,14 @@ nsPresContext::GetFontPreferences() // get font.size-adjust.[generic].[langGroup] // XXX only applicable on GFX ports that handle |font-size-adjust| MAKE_FONT_PREF_KEY(pref, "font.size-adjust", generic_dot_langGroup); - rv = mPrefs->CopyCharPref(pref.get(), getter_Copies(cvalue)); - if (NS_SUCCEEDED(rv)) { + cvalue = nsContentUtils::GetCharPref(pref.get()); + if (!cvalue.IsEmpty()) { font->sizeAdjust = (float)atof(cvalue.get()); } #ifdef DEBUG_rbs printf("%s Family-list:%s size:%d sizeAdjust:%.2f\n", - generic_dot_langGroup.get(), + generic_dot_langGroup.get(), NS_ConvertUCS2toUTF8(font->name).get(), font->size, font->sizeAdjust); #endif @@ -403,8 +408,6 @@ void nsPresContext::GetDocumentColorPreferences() { PRBool usePrefColors = PR_TRUE; - PRBool boolPref; - nsXPIDLCString colorStr; nsCOMPtr docShell(do_QueryReferent(mContainer)); if (docShell) { PRInt32 docShellType; @@ -413,15 +416,23 @@ nsPresContext::GetDocumentColorPreferences() usePrefColors = PR_FALSE; } if (usePrefColors) { - if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.use_system_colors", &boolPref))) { - usePrefColors = !boolPref; - } + usePrefColors = + !nsContentUtils::GetBoolPref("browser.display.use_system_colors", + PR_FALSE); } + if (usePrefColors) { - if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.foreground_color", getter_Copies(colorStr)))) { + nsAdoptingCString colorStr = + nsContentUtils::GetCharPref("browser.display.foreground_color"); + + if (!colorStr.IsEmpty()) { mDefaultColor = MakeColorPref(colorStr); } - if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.background_color", getter_Copies(colorStr)))) { + + colorStr = + nsContentUtils::GetCharPref("browser.display.background_color"); + + if (!colorStr.IsEmpty()) { mBackgroundColor = MakeColorPref(colorStr); } } @@ -434,102 +445,124 @@ nsPresContext::GetDocumentColorPreferences() mBackgroundColor); } - if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.use_document_colors", &boolPref))) { - mUseDocumentColors = boolPref; - } + mUseDocumentColors = + nsContentUtils::GetBoolPref("browser.display.use_document_colors", + mUseDocumentColors); } void nsPresContext::GetUserPreferences() { - PRInt32 prefInt; - - if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.base_font_scaler", &prefInt))) { - mFontScaler = prefInt; - } + mFontScaler = + nsContentUtils::GetIntPref("browser.display.base_font_scaler", + mFontScaler); // * document colors GetDocumentColorPreferences(); // * link colors - PRBool boolPref; - nsXPIDLCString colorStr; - if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.underline_anchors", &boolPref))) { - mUnderlineLinks = boolPref; - } - if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.anchor_color", getter_Copies(colorStr)))) { + mUnderlineLinks = + nsContentUtils::GetBoolPref("browser.underline_anchors", mUnderlineLinks); + + nsAdoptingCString colorStr = + nsContentUtils::GetCharPref("browser.anchor_color"); + + if (!colorStr.IsEmpty()) { mLinkColor = MakeColorPref(colorStr); } - if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.active_color", getter_Copies(colorStr)))) { + + colorStr = + nsContentUtils::GetCharPref("browser.active_color"); + + if (!colorStr.IsEmpty()) { mActiveLinkColor = MakeColorPref(colorStr); } - if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.visited_color", getter_Copies(colorStr)))) { + + colorStr = nsContentUtils::GetCharPref("browser.visited_color"); + + if (!colorStr.IsEmpty()) { mVisitedLinkColor = MakeColorPref(colorStr); } + mUseFocusColors = + nsContentUtils::GetBoolPref("browser.display.use_focus_colors", + mUseFocusColors); - if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.use_focus_colors", &boolPref))) { - mUseFocusColors = boolPref; - mFocusTextColor = mDefaultColor; - mFocusBackgroundColor = mBackgroundColor; - if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.focus_text_color", getter_Copies(colorStr)))) { - mFocusTextColor = MakeColorPref(colorStr); - } - if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.focus_background_color", getter_Copies(colorStr)))) { - mFocusBackgroundColor = MakeColorPref(colorStr); - } + mFocusTextColor = mDefaultColor; + mFocusBackgroundColor = mBackgroundColor; + + colorStr = nsContentUtils::GetCharPref("browser.display.focus_text_color"); + + if (!colorStr.IsEmpty()) { + mFocusTextColor = MakeColorPref(colorStr); } - if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.focus_ring_width", &prefInt))) { - mFocusRingWidth = prefInt; + colorStr = + nsContentUtils::GetCharPref("browser.display.focus_background_color"); + + if (!colorStr.IsEmpty()) { + mFocusBackgroundColor = MakeColorPref(colorStr); } - if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.focus_ring_on_anything", &boolPref))) { - mFocusRingOnAnything = boolPref; - } + mFocusRingWidth = + nsContentUtils::GetIntPref("browser.display.focus_ring_width", + mFocusRingWidth); + + mFocusRingOnAnything = + nsContentUtils::GetBoolPref("browser.display.focus_ring_on_anything", + mFocusRingOnAnything); // * use fonts? - if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.use_document_fonts", &prefInt))) { - mUseDocumentFonts = prefInt == 0 ? PR_FALSE : PR_TRUE; - } - + mUseDocumentFonts = + nsContentUtils::GetIntPref("browser.display.use_document_fonts") != 0; + GetFontPreferences(); // * image animation - 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 (!nsCRT::strcmp(animatePref, "none")) - mImageAnimationModePref = imgIContainer::kDontAnimMode; - else if (!nsCRT::strcmp(animatePref, "once")) - mImageAnimationModePref = imgIContainer::kLoopOnceAnimMode; - nsMemory::Free(animatePref); - } + const nsAdoptingCString& animatePref = + nsContentUtils::GetCharPref("image.animation_mode"); + if (animatePref.Equals("normal")) + mImageAnimationModePref = imgIContainer::kNormalAnimMode; + else if (animatePref.Equals("none")) + mImageAnimationModePref = imgIContainer::kDontAnimMode; + else if (animatePref.Equals("once")) + mImageAnimationModePref = imgIContainer::kLoopOnceAnimMode; #ifdef IBMBIDI - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.direction", &prefInt))) { - SET_BIDI_OPTION_DIRECTION(mBidi, prefInt); - } - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.texttype", &prefInt))) { - SET_BIDI_OPTION_TEXTTYPE(mBidi, prefInt); - } - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.controlstextmode", &prefInt))) { - SET_BIDI_OPTION_CONTROLSTEXTMODE(mBidi, prefInt); - } - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.clipboardtextmode", &prefInt))) { - SET_BIDI_OPTION_CLIPBOARDTEXTMODE(mBidi, prefInt); - } - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.numeral", &prefInt))) { - SET_BIDI_OPTION_NUMERAL(mBidi, prefInt); - } - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.support", &prefInt))) { - SET_BIDI_OPTION_SUPPORT(mBidi, prefInt); - } - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.characterset", &prefInt))) { - SET_BIDI_OPTION_CHARACTERSET(mBidi, prefInt); - } + PRInt32 prefInt = + nsContentUtils::GetIntPref("bidi.direction", + GET_BIDI_OPTION_DIRECTION(mBidi)); + SET_BIDI_OPTION_DIRECTION(mBidi, prefInt); + + prefInt = + nsContentUtils::GetIntPref("bidi.texttype", + GET_BIDI_OPTION_TEXTTYPE(mBidi)); + SET_BIDI_OPTION_TEXTTYPE(mBidi, prefInt); + + prefInt = + nsContentUtils::GetIntPref("bidi.controlstextmode", + GET_BIDI_OPTION_CONTROLSTEXTMODE(mBidi)); + SET_BIDI_OPTION_CONTROLSTEXTMODE(mBidi, prefInt); + + prefInt = + nsContentUtils::GetIntPref("bidi.clipboardtextmode", + GET_BIDI_OPTION_CLIPBOARDTEXTMODE(mBidi)); + SET_BIDI_OPTION_CLIPBOARDTEXTMODE(mBidi, prefInt); + + prefInt = + nsContentUtils::GetIntPref("bidi.numeral", + GET_BIDI_OPTION_NUMERAL(mBidi)); + SET_BIDI_OPTION_NUMERAL(mBidi, prefInt); + + prefInt = + nsContentUtils::GetIntPref("bidi.support", + GET_BIDI_OPTION_SUPPORT(mBidi)); + SET_BIDI_OPTION_SUPPORT(mBidi, prefInt); + + prefInt = + nsContentUtils::GetIntPref("bidi.characterset", + GET_BIDI_OPTION_CHARACTERSET(mBidi)); + SET_BIDI_OPTION_CHARACTERSET(mBidi, prefInt); #endif } @@ -588,32 +621,47 @@ nsPresContext::Init(nsIDeviceContext* aDeviceContext) return rv; } - mLangService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID); - mPrefs = do_GetService(NS_PREF_CONTRACTID); - if (mPrefs) { - // Register callbacks so we're notified when the preferences change - mPrefs->RegisterCallback("font.", nsPresContext::PrefChangedCallback, (void*)this); - mPrefs->RegisterCallback("browser.display.", nsPresContext::PrefChangedCallback, (void*)this); - mPrefs->RegisterCallback("browser.underline_anchors", nsPresContext::PrefChangedCallback, (void*)this); - mPrefs->RegisterCallback("browser.anchor_color", nsPresContext::PrefChangedCallback, (void*)this); - mPrefs->RegisterCallback("browser.active_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 - mPrefs->RegisterCallback("bidi.", PrefChangedCallback, (void*)this); -#endif - - // Initialize our state from the user preferences - GetUserPreferences(); - } - mEventManager = new nsEventStateManager(); if (!mEventManager) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(mEventManager); + mLangService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID); + + // Register callbacks so we're notified when the preferences change + nsContentUtils::RegisterPrefCallback("font.", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::RegisterPrefCallback("browser.display.", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::RegisterPrefCallback("browser.underline_anchors", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::RegisterPrefCallback("browser.anchor_color", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::RegisterPrefCallback("browser.active_color", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::RegisterPrefCallback("browser.visited_color", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::RegisterPrefCallback("network.image.imageBehavior", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::RegisterPrefCallback("image.animation_mode", + nsPresContext::PrefChangedCallback, + this); +#ifdef IBMBIDI + nsContentUtils::RegisterPrefCallback("bidi.", PrefChangedCallback, + this); +#endif + + // Initialize our state from the user preferences + GetUserPreferences(); + rv = mEventManager->Init(); NS_ENSURE_SUCCESS(rv, rv); @@ -1044,7 +1092,8 @@ nsPresContext::GetBidiUtils(nsBidiPresUtils** aBidiUtils) return rv; } -NS_IMETHODIMP nsPresContext::SetBidi(PRUint32 aSource, PRBool aForceReflow) +NS_IMETHODIMP +nsPresContext::SetBidi(PRUint32 aSource, PRBool aForceReflow) { mBidi = aSource; if (IBMBIDI_TEXTDIRECTION_RTL == GET_BIDI_OPTION_DIRECTION(mBidi) @@ -1065,7 +1114,9 @@ NS_IMETHODIMP nsPresContext::SetBidi(PRUint32 aSource, PRBool aForceReflow) } return NS_OK; } -NS_IMETHODIMP nsPresContext::GetBidi(PRUint32* aDest) const + +NS_IMETHODIMP +nsPresContext::GetBidi(PRUint32* aDest) const { if (aDest) *aDest = mBidi; diff --git a/mozilla/layout/base/nsPresContext.h b/mozilla/layout/base/nsPresContext.h index afe34abf698..893a3a61fcf 100644 --- a/mozilla/layout/base/nsPresContext.h +++ b/mozilla/layout/base/nsPresContext.h @@ -64,11 +64,8 @@ class nsIFrame; class nsFrameManager; class nsIImage; class nsILinkHandler; -class nsIPresShell; -class nsIPref; class nsStyleContext; class nsIAtom; -class nsString; class nsIEventStateManager; class nsIURI; class nsILookAndFeel; diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index 8f8d877e858..d963f39b235 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -74,8 +74,6 @@ #include "prinrval.h" #include "nsVoidArray.h" #include "nsHashtable.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" #include "nsIViewObserver.h" #include "nsContainerFrame.h" #include "nsIDeviceContext.h" @@ -83,6 +81,7 @@ #include "nsIDOMEvent.h" #include "nsGUIEvent.h" #include "nsHTMLParts.h" +#include "nsContentUtils.h" #include "nsISelection.h" #include "nsISelectionController.h" #include "nsReflowPath.h" @@ -1774,17 +1773,13 @@ PresShell::Init(nsIDocument* aDocument, } if (gMaxRCProcessingTime == -1) { - // First, set the defaults - gMaxRCProcessingTime = NS_MAX_REFLOW_TIME; - gAsyncReflowDuringDocLoad = PR_TRUE; + gMaxRCProcessingTime = + nsContentUtils::GetIntPref("layout.reflow.timeslice", + NS_MAX_REFLOW_TIME); - // 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); - } + gAsyncReflowDuringDocLoad = + nsContentUtils::GetBoolPref("layout.reflow.async.duringDocLoad", + PR_TRUE); } // cache the observation service @@ -1804,23 +1799,18 @@ PresShell::Init(nsIDocument* aDocument, #ifdef MOZ_REFLOW_PERF if (mReflowCountMgr) { - // Get the prefs service - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - PRBool paintFrameCounts = PR_FALSE; - PRBool dumpFrameCounts = PR_FALSE; - PRBool dumpFrameByFrameCounts = PR_FALSE; - prefBranch->GetBoolPref("layout.reflow.showframecounts", - &paintFrameCounts); - prefBranch->GetBoolPref("layout.reflow.dumpframecounts", - &dumpFrameCounts); - prefBranch->GetBoolPref("layout.reflow.dumpframebyframecounts", - &dumpFrameByFrameCounts); + PRBool paintFrameCounts = + nsContentUtils::GetBoolPref("layout.reflow.showframecounts"); - mReflowCountMgr->SetDumpFrameCounts(dumpFrameCounts); - mReflowCountMgr->SetDumpFrameByFrameCounts(dumpFrameByFrameCounts); - mReflowCountMgr->SetPaintFrameCounts(paintFrameCounts); - } + PRBool dumpFrameCounts = + nsContentUtils::GetBoolPref("layout.reflow.dumpframecounts"); + + PRBool dumpFrameByFrameCounts = + nsContentUtils::GetBoolPref("layout.reflow.dumpframebyframecounts"); + + mReflowCountMgr->SetDumpFrameCounts(dumpFrameCounts); + mReflowCountMgr->SetDumpFrameByFrameCounts(dumpFrameByFrameCounts); + mReflowCountMgr->SetPaintFrameCounts(paintFrameCounts); } #endif @@ -2892,15 +2882,17 @@ PresShell::InitialReflow(nscoord aWidth, nscoord aHeight) mPaintingSuppressed = PR_FALSE; 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); + + // Default to PAINTLOCK_EVENT_DELAY if we can't get the pref value. + PRInt32 delay = + nsContentUtils::GetIntPref("nglayout.initialpaint.delay", + PAINTLOCK_EVENT_DELAY); nsCOMPtr ti = do_QueryInterface(mPaintSuppressionTimer); ti->SetIdle(PR_FALSE); - mPaintSuppressionTimer->InitWithFuncCallback(sPaintSuppressionCallback, this, delay, + mPaintSuppressionTimer->InitWithFuncCallback(sPaintSuppressionCallback, + this, delay, nsITimer::TYPE_ONE_SHOT); } } @@ -4059,15 +4051,14 @@ PresShell::GoToAnchor(const nsAString& aAnchorName, PRBool aScroll) NS_PRESSHELL_SCROLL_ANYWHERE); if (NS_SUCCEEDED(rv)) { - // 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); - } - // Even if select anchor pref is false, we must still move the caret there. - // That way tabbing will start from the new location + // Should we select the target? This action is controlled by a + // preference: the default is to not select. + PRBool selectAnchor = + nsContentUtils::GetBoolPref("layout.selectanchor"); + + // Even if select anchor pref is false, we must still move the + // caret there. That way tabbing will start from the new + // location if (!jumpToRange) { jumpToRange = do_CreateInstance(kRangeCID); nsCOMPtr node(do_QueryInterface(content)); diff --git a/mozilla/layout/base/public/nsIPresContext.h b/mozilla/layout/base/public/nsIPresContext.h index afe34abf698..893a3a61fcf 100644 --- a/mozilla/layout/base/public/nsIPresContext.h +++ b/mozilla/layout/base/public/nsIPresContext.h @@ -64,11 +64,8 @@ class nsIFrame; class nsFrameManager; class nsIImage; class nsILinkHandler; -class nsIPresShell; -class nsIPref; class nsStyleContext; class nsIAtom; -class nsString; class nsIEventStateManager; class nsIURI; class nsILookAndFeel; diff --git a/mozilla/layout/base/public/nsPresContext.h b/mozilla/layout/base/public/nsPresContext.h index afe34abf698..893a3a61fcf 100644 --- a/mozilla/layout/base/public/nsPresContext.h +++ b/mozilla/layout/base/public/nsPresContext.h @@ -64,11 +64,8 @@ class nsIFrame; class nsFrameManager; class nsIImage; class nsILinkHandler; -class nsIPresShell; -class nsIPref; class nsStyleContext; class nsIAtom; -class nsString; class nsIEventStateManager; class nsIURI; class nsILookAndFeel; diff --git a/mozilla/layout/base/src/Makefile.in b/mozilla/layout/base/src/Makefile.in index c392d12433e..ca536d0b870 100644 --- a/mozilla/layout/base/src/Makefile.in +++ b/mozilla/layout/base/src/Makefile.in @@ -59,6 +59,8 @@ REQUIRES = xpcom \ uriloader \ docshell \ imglib2 \ + js \ + xpconnect \ $(NULL) CPPSRCS = \ diff --git a/mozilla/layout/base/src/nsPresContext.cpp b/mozilla/layout/base/src/nsPresContext.cpp index 19c7a25be1b..475f6d72921 100644 --- a/mozilla/layout/base/src/nsPresContext.cpp +++ b/mozilla/layout/base/src/nsPresContext.cpp @@ -37,7 +37,6 @@ #include "nsCOMPtr.h" #include "nsPresContext.h" #include "nsIPresShell.h" -#include "nsIPref.h" #include "nsILinkHandler.h" #include "nsIDocShellTreeItem.h" #include "nsStyleSet.h" @@ -73,6 +72,8 @@ #include "nsBidiPresUtils.h" #endif // IBMBIDI +#include "nsContentUtils.h" + // Needed for Start/Stop of Image Animation #include "imgIContainer.h" #include "nsIImageLoadingContent.h" @@ -134,6 +135,8 @@ static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); #include "nsContentCID.h" static NS_DEFINE_CID(kSelectionImageService, NS_SELECTIONIMAGESERVICE_CID); + // NOTE! nsPresContext::operator new() zeroes out all members, so don't + // bother initializing members to 0. nsPresContext::nsPresContext() : mDefaultVariableFont("serif", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, @@ -151,6 +154,10 @@ nsPresContext::nsPresContext() mDefaultFantasyFont("fantasy", NS_FONT_STYLE_NORMAL, NS_FONT_VARIANT_NORMAL, NS_FONT_WEIGHT_NORMAL, 0, NSIntPointsToTwips(12)) { + + // NOTE! nsPresContext::operator new() zeroes out all members, so don't + // bother initializing members to 0. + mCompatibilityMode = eCompatibility_FullStandards; mImageAnimationMode = imgIContainer::kNormalAnimMode; mImageAnimationModePref = imgIContainer::kNormalAnimMode; @@ -158,40 +165,25 @@ nsPresContext::nsPresContext() SetBackgroundImageDraw(PR_TRUE); // always draw the background SetBackgroundColorDraw(PR_TRUE); - mShell = nsnull; - mLinkHandler = nsnull; - mContainer = nsnull; - mViewportStyleOverflow = NS_STYLE_OVERFLOW_AUTO; - mDefaultColor = NS_RGB(0x00, 0x00, 0x00); mBackgroundColor = NS_RGB(0xFF, 0xFF, 0xFF); mUseDocumentColors = PR_TRUE; mUseDocumentFonts = PR_TRUE; // the minimum font-size is unconstrained by default - mMinimumFontSize = 0; mLinkColor = NS_RGB(0x00, 0x00, 0xEE); mActiveLinkColor = NS_RGB(0xEE, 0x00, 0x00); mVisitedLinkColor = NS_RGB(0x55, 0x1A, 0x8B); mUnderlineLinks = PR_TRUE; - mUseFocusColors = PR_FALSE; mFocusTextColor = mDefaultColor; mFocusBackgroundColor = mBackgroundColor; mFocusRingWidth = 1; - mFocusRingOnAnything = PR_FALSE; mLanguageSpecificTransformType = eLanguageSpecificTransformType_Unknown; - mIsRenderingOnlySelection = PR_FALSE; -#ifdef IBMBIDI - mIsVisual = PR_FALSE; - mBidiUtils = nsnull; - mIsBidiSystem = PR_FALSE; - mBidi = 0; -#endif // IBMBIDI } nsPresContext::~nsPresContext() @@ -207,23 +199,34 @@ nsPresContext::~nsPresContext() } // 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.active_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); + nsContentUtils::UnregisterPrefCallback("font.", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::UnregisterPrefCallback("browser.display.", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::UnregisterPrefCallback("browser.underline_anchors", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::UnregisterPrefCallback("browser.anchor_color", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::UnregisterPrefCallback("browser.active_color", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::UnregisterPrefCallback("browser.visited_color", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::UnregisterPrefCallback("network.image.imageBehavior", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::UnregisterPrefCallback("image.animation_mode", + nsPresContext::PrefChangedCallback, + this); #ifdef IBMBIDI - mPrefs->UnregisterCallback("bidi.", PrefChangedCallback, (void*)this); -#endif - } -#ifdef IBMBIDI - if (mBidiUtils) { - delete mBidiUtils; - } + nsContentUtils::UnregisterPrefCallback("bidi.", PrefChangedCallback, this); + + delete mBidiUtils; #endif // IBMBIDI NS_IF_RELEASE(mDeviceContext); @@ -250,7 +253,7 @@ static const char* const kGenericFont[] = { void nsPresContext::GetFontPreferences() { - if (!mPrefs || !mLanguage) + if (!mLanguage) return; /* Fetch the font prefs to be used -- see bug 61883 for details. @@ -280,18 +283,19 @@ nsPresContext::GetFontPreferences() langGroupAtom->ToString(langGroup); nsCAutoString pref; - nsXPIDLString value; - nsXPIDLCString cvalue; // get the current applicable font-size unit enum {eUnit_unknown = -1, eUnit_px, eUnit_pt}; PRInt32 unit = eUnit_px; - nsresult rv = mPrefs->CopyCharPref("font.size.unit", getter_Copies(cvalue)); - if (NS_SUCCEEDED(rv)) { - if (!PL_strcmp(cvalue.get(), "px")) { + + nsAdoptingCString cvalue = + nsContentUtils::GetCharPref("font.size.unit"); + + if (!cvalue.IsEmpty()) { + if (cvalue.Equals("px")) { unit = eUnit_px; } - else if (!PL_strcmp(cvalue.get(), "pt")) { + else if (cvalue.Equals("pt")) { unit = eUnit_pt; } else { @@ -301,13 +305,12 @@ nsPresContext::GetFontPreferences() } // get font.minimum-size.[langGroup] - PRInt32 size; pref.Assign("font.minimum-size."); AppendUTF16toUTF8(langGroup, pref); - rv = mPrefs->GetIntPref(pref.get(), &size); - if (NS_SUCCEEDED(rv)) { + PRInt32 size = nsContentUtils::GetIntPref(pref.get()); + if (size > 0) { if (unit == eUnit_px) { mMinimumFontSize = NSFloatPixelsToTwips((float)size, p2t); } @@ -338,13 +341,15 @@ nsPresContext::GetFontPreferences() // in GFX and will be queried there when hunting for alternative fonts) if (eType == eDefaultFont_Variable) { MAKE_FONT_PREF_KEY(pref, "font.name", generic_dot_langGroup); - rv = mPrefs->CopyUnicharPref(pref.get(), getter_Copies(value)); - if (NS_SUCCEEDED(rv)) { + + nsAdoptingString value = + nsContentUtils::GetStringPref(pref.get()); + if (!value.IsEmpty()) { font->name.Assign(value); } else { - rv = mPrefs->CopyUnicharPref("font.default", getter_Copies(value)); - if (NS_SUCCEEDED(rv)) { + value = nsContentUtils::GetStringPref("font.default"); + if (!value.IsEmpty()) { mDefaultVariableFont.name.Assign(value); } } @@ -372,8 +377,8 @@ nsPresContext::GetFontPreferences() // get font.size.[generic].[langGroup] // size=0 means 'Auto', i.e., generic fonts retain the size of the variable font MAKE_FONT_PREF_KEY(pref, "font.size", generic_dot_langGroup); - rv = mPrefs->GetIntPref(pref.get(), &size); - if (NS_SUCCEEDED(rv) && size > 0) { + size = nsContentUtils::GetIntPref(pref.get()); + if (size > 0) { if (unit == eUnit_px) { font->size = NSFloatPixelsToTwips((float)size, p2t); } @@ -385,14 +390,14 @@ nsPresContext::GetFontPreferences() // get font.size-adjust.[generic].[langGroup] // XXX only applicable on GFX ports that handle |font-size-adjust| MAKE_FONT_PREF_KEY(pref, "font.size-adjust", generic_dot_langGroup); - rv = mPrefs->CopyCharPref(pref.get(), getter_Copies(cvalue)); - if (NS_SUCCEEDED(rv)) { + cvalue = nsContentUtils::GetCharPref(pref.get()); + if (!cvalue.IsEmpty()) { font->sizeAdjust = (float)atof(cvalue.get()); } #ifdef DEBUG_rbs printf("%s Family-list:%s size:%d sizeAdjust:%.2f\n", - generic_dot_langGroup.get(), + generic_dot_langGroup.get(), NS_ConvertUCS2toUTF8(font->name).get(), font->size, font->sizeAdjust); #endif @@ -403,8 +408,6 @@ void nsPresContext::GetDocumentColorPreferences() { PRBool usePrefColors = PR_TRUE; - PRBool boolPref; - nsXPIDLCString colorStr; nsCOMPtr docShell(do_QueryReferent(mContainer)); if (docShell) { PRInt32 docShellType; @@ -413,15 +416,23 @@ nsPresContext::GetDocumentColorPreferences() usePrefColors = PR_FALSE; } if (usePrefColors) { - if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.use_system_colors", &boolPref))) { - usePrefColors = !boolPref; - } + usePrefColors = + !nsContentUtils::GetBoolPref("browser.display.use_system_colors", + PR_FALSE); } + if (usePrefColors) { - if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.foreground_color", getter_Copies(colorStr)))) { + nsAdoptingCString colorStr = + nsContentUtils::GetCharPref("browser.display.foreground_color"); + + if (!colorStr.IsEmpty()) { mDefaultColor = MakeColorPref(colorStr); } - if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.background_color", getter_Copies(colorStr)))) { + + colorStr = + nsContentUtils::GetCharPref("browser.display.background_color"); + + if (!colorStr.IsEmpty()) { mBackgroundColor = MakeColorPref(colorStr); } } @@ -434,102 +445,124 @@ nsPresContext::GetDocumentColorPreferences() mBackgroundColor); } - if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.use_document_colors", &boolPref))) { - mUseDocumentColors = boolPref; - } + mUseDocumentColors = + nsContentUtils::GetBoolPref("browser.display.use_document_colors", + mUseDocumentColors); } void nsPresContext::GetUserPreferences() { - PRInt32 prefInt; - - if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.base_font_scaler", &prefInt))) { - mFontScaler = prefInt; - } + mFontScaler = + nsContentUtils::GetIntPref("browser.display.base_font_scaler", + mFontScaler); // * document colors GetDocumentColorPreferences(); // * link colors - PRBool boolPref; - nsXPIDLCString colorStr; - if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.underline_anchors", &boolPref))) { - mUnderlineLinks = boolPref; - } - if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.anchor_color", getter_Copies(colorStr)))) { + mUnderlineLinks = + nsContentUtils::GetBoolPref("browser.underline_anchors", mUnderlineLinks); + + nsAdoptingCString colorStr = + nsContentUtils::GetCharPref("browser.anchor_color"); + + if (!colorStr.IsEmpty()) { mLinkColor = MakeColorPref(colorStr); } - if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.active_color", getter_Copies(colorStr)))) { + + colorStr = + nsContentUtils::GetCharPref("browser.active_color"); + + if (!colorStr.IsEmpty()) { mActiveLinkColor = MakeColorPref(colorStr); } - if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.visited_color", getter_Copies(colorStr)))) { + + colorStr = nsContentUtils::GetCharPref("browser.visited_color"); + + if (!colorStr.IsEmpty()) { mVisitedLinkColor = MakeColorPref(colorStr); } + mUseFocusColors = + nsContentUtils::GetBoolPref("browser.display.use_focus_colors", + mUseFocusColors); - if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.use_focus_colors", &boolPref))) { - mUseFocusColors = boolPref; - mFocusTextColor = mDefaultColor; - mFocusBackgroundColor = mBackgroundColor; - if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.focus_text_color", getter_Copies(colorStr)))) { - mFocusTextColor = MakeColorPref(colorStr); - } - if (NS_SUCCEEDED(mPrefs->CopyCharPref("browser.display.focus_background_color", getter_Copies(colorStr)))) { - mFocusBackgroundColor = MakeColorPref(colorStr); - } + mFocusTextColor = mDefaultColor; + mFocusBackgroundColor = mBackgroundColor; + + colorStr = nsContentUtils::GetCharPref("browser.display.focus_text_color"); + + if (!colorStr.IsEmpty()) { + mFocusTextColor = MakeColorPref(colorStr); } - if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.focus_ring_width", &prefInt))) { - mFocusRingWidth = prefInt; + colorStr = + nsContentUtils::GetCharPref("browser.display.focus_background_color"); + + if (!colorStr.IsEmpty()) { + mFocusBackgroundColor = MakeColorPref(colorStr); } - if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.focus_ring_on_anything", &boolPref))) { - mFocusRingOnAnything = boolPref; - } + mFocusRingWidth = + nsContentUtils::GetIntPref("browser.display.focus_ring_width", + mFocusRingWidth); + + mFocusRingOnAnything = + nsContentUtils::GetBoolPref("browser.display.focus_ring_on_anything", + mFocusRingOnAnything); // * use fonts? - if (NS_SUCCEEDED(mPrefs->GetIntPref("browser.display.use_document_fonts", &prefInt))) { - mUseDocumentFonts = prefInt == 0 ? PR_FALSE : PR_TRUE; - } - + mUseDocumentFonts = + nsContentUtils::GetIntPref("browser.display.use_document_fonts") != 0; + GetFontPreferences(); // * image animation - 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 (!nsCRT::strcmp(animatePref, "none")) - mImageAnimationModePref = imgIContainer::kDontAnimMode; - else if (!nsCRT::strcmp(animatePref, "once")) - mImageAnimationModePref = imgIContainer::kLoopOnceAnimMode; - nsMemory::Free(animatePref); - } + const nsAdoptingCString& animatePref = + nsContentUtils::GetCharPref("image.animation_mode"); + if (animatePref.Equals("normal")) + mImageAnimationModePref = imgIContainer::kNormalAnimMode; + else if (animatePref.Equals("none")) + mImageAnimationModePref = imgIContainer::kDontAnimMode; + else if (animatePref.Equals("once")) + mImageAnimationModePref = imgIContainer::kLoopOnceAnimMode; #ifdef IBMBIDI - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.direction", &prefInt))) { - SET_BIDI_OPTION_DIRECTION(mBidi, prefInt); - } - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.texttype", &prefInt))) { - SET_BIDI_OPTION_TEXTTYPE(mBidi, prefInt); - } - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.controlstextmode", &prefInt))) { - SET_BIDI_OPTION_CONTROLSTEXTMODE(mBidi, prefInt); - } - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.clipboardtextmode", &prefInt))) { - SET_BIDI_OPTION_CLIPBOARDTEXTMODE(mBidi, prefInt); - } - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.numeral", &prefInt))) { - SET_BIDI_OPTION_NUMERAL(mBidi, prefInt); - } - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.support", &prefInt))) { - SET_BIDI_OPTION_SUPPORT(mBidi, prefInt); - } - if (NS_SUCCEEDED(mPrefs->GetIntPref("bidi.characterset", &prefInt))) { - SET_BIDI_OPTION_CHARACTERSET(mBidi, prefInt); - } + PRInt32 prefInt = + nsContentUtils::GetIntPref("bidi.direction", + GET_BIDI_OPTION_DIRECTION(mBidi)); + SET_BIDI_OPTION_DIRECTION(mBidi, prefInt); + + prefInt = + nsContentUtils::GetIntPref("bidi.texttype", + GET_BIDI_OPTION_TEXTTYPE(mBidi)); + SET_BIDI_OPTION_TEXTTYPE(mBidi, prefInt); + + prefInt = + nsContentUtils::GetIntPref("bidi.controlstextmode", + GET_BIDI_OPTION_CONTROLSTEXTMODE(mBidi)); + SET_BIDI_OPTION_CONTROLSTEXTMODE(mBidi, prefInt); + + prefInt = + nsContentUtils::GetIntPref("bidi.clipboardtextmode", + GET_BIDI_OPTION_CLIPBOARDTEXTMODE(mBidi)); + SET_BIDI_OPTION_CLIPBOARDTEXTMODE(mBidi, prefInt); + + prefInt = + nsContentUtils::GetIntPref("bidi.numeral", + GET_BIDI_OPTION_NUMERAL(mBidi)); + SET_BIDI_OPTION_NUMERAL(mBidi, prefInt); + + prefInt = + nsContentUtils::GetIntPref("bidi.support", + GET_BIDI_OPTION_SUPPORT(mBidi)); + SET_BIDI_OPTION_SUPPORT(mBidi, prefInt); + + prefInt = + nsContentUtils::GetIntPref("bidi.characterset", + GET_BIDI_OPTION_CHARACTERSET(mBidi)); + SET_BIDI_OPTION_CHARACTERSET(mBidi, prefInt); #endif } @@ -588,32 +621,47 @@ nsPresContext::Init(nsIDeviceContext* aDeviceContext) return rv; } - mLangService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID); - mPrefs = do_GetService(NS_PREF_CONTRACTID); - if (mPrefs) { - // Register callbacks so we're notified when the preferences change - mPrefs->RegisterCallback("font.", nsPresContext::PrefChangedCallback, (void*)this); - mPrefs->RegisterCallback("browser.display.", nsPresContext::PrefChangedCallback, (void*)this); - mPrefs->RegisterCallback("browser.underline_anchors", nsPresContext::PrefChangedCallback, (void*)this); - mPrefs->RegisterCallback("browser.anchor_color", nsPresContext::PrefChangedCallback, (void*)this); - mPrefs->RegisterCallback("browser.active_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 - mPrefs->RegisterCallback("bidi.", PrefChangedCallback, (void*)this); -#endif - - // Initialize our state from the user preferences - GetUserPreferences(); - } - mEventManager = new nsEventStateManager(); if (!mEventManager) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(mEventManager); + mLangService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID); + + // Register callbacks so we're notified when the preferences change + nsContentUtils::RegisterPrefCallback("font.", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::RegisterPrefCallback("browser.display.", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::RegisterPrefCallback("browser.underline_anchors", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::RegisterPrefCallback("browser.anchor_color", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::RegisterPrefCallback("browser.active_color", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::RegisterPrefCallback("browser.visited_color", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::RegisterPrefCallback("network.image.imageBehavior", + nsPresContext::PrefChangedCallback, + this); + nsContentUtils::RegisterPrefCallback("image.animation_mode", + nsPresContext::PrefChangedCallback, + this); +#ifdef IBMBIDI + nsContentUtils::RegisterPrefCallback("bidi.", PrefChangedCallback, + this); +#endif + + // Initialize our state from the user preferences + GetUserPreferences(); + rv = mEventManager->Init(); NS_ENSURE_SUCCESS(rv, rv); @@ -1044,7 +1092,8 @@ nsPresContext::GetBidiUtils(nsBidiPresUtils** aBidiUtils) return rv; } -NS_IMETHODIMP nsPresContext::SetBidi(PRUint32 aSource, PRBool aForceReflow) +NS_IMETHODIMP +nsPresContext::SetBidi(PRUint32 aSource, PRBool aForceReflow) { mBidi = aSource; if (IBMBIDI_TEXTDIRECTION_RTL == GET_BIDI_OPTION_DIRECTION(mBidi) @@ -1065,7 +1114,9 @@ NS_IMETHODIMP nsPresContext::SetBidi(PRUint32 aSource, PRBool aForceReflow) } return NS_OK; } -NS_IMETHODIMP nsPresContext::GetBidi(PRUint32* aDest) const + +NS_IMETHODIMP +nsPresContext::GetBidi(PRUint32* aDest) const { if (aDest) *aDest = mBidi; diff --git a/mozilla/layout/base/src/nsPresContext.h b/mozilla/layout/base/src/nsPresContext.h index b95ddb95d54..9125c0e94f2 100644 --- a/mozilla/layout/base/src/nsPresContext.h +++ b/mozilla/layout/base/src/nsPresContext.h @@ -43,7 +43,6 @@ #include "nsFont.h" #include "nsCRT.h" #include "nsCOMPtr.h" -#include "nsIPref.h" #include "nsICharsetConverterManager.h" #include "nsILanguageAtomService.h" #include "nsIURL.h" @@ -121,7 +120,6 @@ protected: nsPresContext(); virtual ~nsPresContext(); - nsCOMPtr mPrefs; nsCOMPtr mLangService; nsWeakPtr mContainer; diff --git a/mozilla/layout/generic/nsFrame.cpp b/mozilla/layout/generic/nsFrame.cpp index f35c6c1e054..ea72eaff02e 100644 --- a/mozilla/layout/generic/nsFrame.cpp +++ b/mozilla/layout/generic/nsFrame.cpp @@ -41,6 +41,7 @@ #include "nsFrameList.h" #include "nsLineLayout.h" #include "nsIContent.h" +#include "nsContentUtils.h" #include "nsIAtom.h" #include "nsString.h" #include "nsReadableUtils.h" @@ -92,8 +93,6 @@ #include "nsIPercentHeightObserver.h" // For triple-click pref -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" #include "nsIServiceManager.h" #include "nsISelectionImageService.h" #include "imgIContainer.h" @@ -1610,9 +1609,8 @@ 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); + selectPara = + nsContentUtils::GetBoolPref("browser.triple_click_selects_paragraph"); } else return NS_OK; diff --git a/mozilla/layout/generic/nsFrameSetFrame.cpp b/mozilla/layout/generic/nsFrameSetFrame.cpp index 475dc5138a0..ab2c3e810cb 100644 --- a/mozilla/layout/generic/nsFrameSetFrame.cpp +++ b/mozilla/layout/generic/nsFrameSetFrame.cpp @@ -37,6 +37,7 @@ * ***** END LICENSE BLOCK ***** */ #include "nsCOMPtr.h" #include "nsFrameSetFrame.h" +#include "nsContentUtils.h" #include "nsIHTMLContent.h" #include "nsLeafFrame.h" #include "nsHTMLContainerFrame.h" @@ -63,9 +64,6 @@ #include "nsIComponentManager.h" #include "nsGUIEvent.h" #include "nsIRenderingContext.h" -#include "nsIPrefService.h" -#include "nsIPrefBranch.h" -#include "nsIPrefBranchInternal.h" #include "nsIServiceManager.h" #include "nsIDOMMutationEvent.h" #include "nsINameSpaceManager.h" @@ -82,7 +80,7 @@ #define ALL_VIS 0x000F #define NONE_VIS 0x0000 -static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); +static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); /******************************************************************************* * nsFramesetDrag @@ -241,32 +239,17 @@ nsHTMLFramesetFrame::nsHTMLFramesetFrame() mChildFrameborder = nsnull; mChildBorderColors = nsnull; mForceFrameResizability = PR_FALSE; - mPrefBranchWeakRef = nsnull; } nsHTMLFramesetFrame::~nsHTMLFramesetFrame() { - delete [] mRowSizes; - delete [] mColSizes; + delete[] mRowSizes; + delete[] mColSizes; delete[] mVerBorders; delete[] mHorBorders; - mRowSizes = mColSizes = nsnull; - - nsCOMPtr prefBranch = - do_QueryReferent(mPrefBranchWeakRef); - - if (prefBranch) { -#ifdef DEBUG - nsresult rv = -#endif - prefBranch->RemoveObserver(kFrameResizePref, this); - - NS_ASSERTION(NS_SUCCEEDED(rv), - "Can't remove frameset as pref branch observer"); - } - - mPrefBranchWeakRef = nsnull; + nsContentUtils::UnregisterPrefCallback(kFrameResizePref, + FrameResizePrefCallback, this); } nsresult nsHTMLFramesetFrame::QueryInterface(const nsIID& aIID, @@ -274,10 +257,9 @@ nsresult nsHTMLFramesetFrame::QueryInterface(const nsIID& aIID, { if (NULL == aInstancePtr) { return NS_ERROR_NULL_POINTER; - } else if (aIID.Equals(NS_GET_IID(nsHTMLFramesetFrame))) { - *aInstancePtr = (void*)this; - return NS_OK; - } else if (aIID.Equals(NS_GET_IID(nsIObserver))) { + } + + if (aIID.Equals(NS_GET_IID(nsHTMLFramesetFrame))) { *aInstancePtr = (void*)this; return NS_OK; } @@ -285,42 +267,34 @@ nsresult nsHTMLFramesetFrame::QueryInterface(const nsIID& aIID, return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr); } -nsrefcnt nsHTMLFramesetFrame::AddRef(void) +// static +int +nsHTMLFramesetFrame::FrameResizePrefCallback(const char* aPref, void* aClosure) { - return 0; -} + nsHTMLFramesetFrame *frame = + NS_REINTERPRET_CAST(nsHTMLFramesetFrame *, aClosure); -nsrefcnt nsHTMLFramesetFrame::Release(void) -{ - return 0; -} - -NS_IMETHODIMP -nsHTMLFramesetFrame::Observe(nsISupports* aObject, const char* aAction, - const PRUnichar* aPrefName) -{ - nsAutoString prefName(aPrefName); - if (prefName.Equals(NS_LITERAL_STRING(kFrameResizePref))) { - nsIDocument* doc = mContent->GetDocument(); - mozAutoDocUpdate updateBatch(doc, UPDATE_CONTENT_MODEL, PR_TRUE); - if (doc) { - doc->AttributeWillChange(mContent, - kNameSpaceID_None, - nsHTMLAtoms::frameborder); - } - nsCOMPtr prefBranch(do_QueryInterface(aObject)); - if (prefBranch) { - prefBranch->GetBoolPref(kFrameResizePref, &mForceFrameResizability); - } - RecalculateBorderResize(); - if (doc) { - doc->AttributeChanged(mContent, - kNameSpaceID_None, - nsHTMLAtoms::frameborder, - nsIDOMMutationEvent::MODIFICATION); - } + nsIDocument* doc = frame->mContent->GetDocument(); + mozAutoDocUpdate updateBatch(doc, UPDATE_CONTENT_MODEL, PR_TRUE); + if (doc) { + doc->AttributeWillChange(frame->mContent, + kNameSpaceID_None, + nsHTMLAtoms::frameborder); } - return NS_OK; + + frame->mForceFrameResizability = + nsContentUtils::GetBoolPref(kFrameResizePref, + frame->mForceFrameResizability); + + frame->RecalculateBorderResize(); + if (doc) { + doc->AttributeChanged(frame->mContent, + kNameSpaceID_None, + nsHTMLAtoms::frameborder, + nsIDOMMutationEvent::MODIFICATION); + } + + return 0; } static NS_DEFINE_IID(kViewCID, NS_VIEW_CID); @@ -997,12 +971,10 @@ nsHTMLFramesetFrame::Reflow(nsIPresContext* aPresContext, PRBool firstTime = (eReflowReason_Initial == aReflowState.reason); if (firstTime) { - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - mPrefBranchWeakRef = do_GetWeakReference(prefBranch); - prefBranch->AddObserver(kFrameResizePref, this, PR_FALSE); - prefBranch->GetBoolPref(kFrameResizePref, &mForceFrameResizability); - } + nsContentUtils::RegisterPrefCallback(kFrameResizePref, + FrameResizePrefCallback, this); + mForceFrameResizability = + nsContentUtils::GetBoolPref(kFrameResizePref); } // subtract out the width of all of the potential borders. There are diff --git a/mozilla/layout/generic/nsFrameSetFrame.h b/mozilla/layout/generic/nsFrameSetFrame.h index e424b8fa27b..f59c059f2ac 100644 --- a/mozilla/layout/generic/nsFrameSetFrame.h +++ b/mozilla/layout/generic/nsFrameSetFrame.h @@ -103,8 +103,7 @@ struct nsFramesetDrag { /******************************************************************************* * nsHTMLFramesetFrame ******************************************************************************/ -class nsHTMLFramesetFrame : public nsHTMLContainerFrame, - public nsIObserver +class nsHTMLFramesetFrame : public nsHTMLContainerFrame { public: // Woohoo, concrete class with an IID! @@ -114,8 +113,7 @@ public: virtual ~nsHTMLFramesetFrame(); - NS_DECL_ISUPPORTS - NS_DECL_NSIOBSERVER + NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); NS_IMETHOD Init(nsIPresContext* aPresContext, nsIContent* aContent, @@ -243,6 +241,8 @@ protected: PRBool ChildIsFrameset(nsIFrame* aChild); + static int FrameResizePrefCallback(const char* aPref, void* aClosure); + PRInt32 mNumRows; nscoord* mRowSizes; // currently computed row sizes PRInt32 mNumCols; @@ -271,7 +271,6 @@ protected: nsBorderColor* mChildBorderColors; PRBool mForceFrameResizability; - nsWeakPtr mPrefBranchWeakRef; }; diff --git a/mozilla/layout/generic/nsHTMLReflowState.cpp b/mozilla/layout/generic/nsHTMLReflowState.cpp index 876c362b0ec..1f7b9e5999f 100644 --- a/mozilla/layout/generic/nsHTMLReflowState.cpp +++ b/mozilla/layout/generic/nsHTMLReflowState.cpp @@ -49,9 +49,9 @@ #include "nsBlockFrame.h" #include "nsLineBox.h" #include "nsImageFrame.h" -#include "nsIPref.h" #include "nsIServiceManager.h" #include "nsIPercentHeightObserver.h" +#include "nsContentUtils.h" #ifdef IBMBIDI #include "nsBidiUtils.h" #endif @@ -1519,14 +1519,12 @@ nsHTMLReflowState::ComputeContainingBlockRectangle(nsIPresContext* aPre } // Prefs callback to pick up changes -static int PR_CALLBACK PrefsChanged(const char *aPrefName, void *instance) +PR_STATIC_CALLBACK(int) +PrefsChanged(const char *aPrefName, void *instance) { - nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID); - if (prefs) { - PRBool boolPref; - if (NS_SUCCEEDED(prefs->GetBoolPref("browser.blink_allowed", &boolPref))) - sBlinkIsAllowed = boolPref; - } + sBlinkIsAllowed = + nsContentUtils::GetBoolPref("browser.blink_allowed", sBlinkIsAllowed); + return 0; /* PREF_OK */ } @@ -1537,11 +1535,8 @@ static PRBool BlinkIsAllowed(void) { if (!sPrefIsLoaded) { // Set up a listener and check the initial value - nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID); - if (prefs) { - prefs->RegisterCallback("browser.blink_allowed", PrefsChanged, - nsnull); - } + nsContentUtils::RegisterPrefCallback("browser.blink_allowed", PrefsChanged, + nsnull); PrefsChanged(nsnull, nsnull); sPrefIsLoaded = PR_TRUE; } @@ -1552,15 +1547,11 @@ static PRBool BlinkIsAllowed(void) static eNormalLineHeightControl GetNormalLineHeightCalcControl(void) { if (sNormalLineHeightControl == eUninitialized) { - 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 (prefs && NS_SUCCEEDED(prefs->GetIntPref( - "browser.display.normal_lineheight_calc_control", &intPref))) - sNormalLineHeightControl = NS_STATIC_CAST(eNormalLineHeightControl, intPref); - else - sNormalLineHeightControl = eNoExternalLeading; + // browser.display.normal_lineheight_calc_control is not user + // changable, so no need to register callback for it. + sNormalLineHeightControl = + NS_STATIC_CAST(eNormalLineHeightControl, + nsContentUtils::GetIntPref("browser.display.normal_lineheight_calc_control", eNoExternalLeading)); } return sNormalLineHeightControl; } diff --git a/mozilla/layout/generic/nsImageFrame.cpp b/mozilla/layout/generic/nsImageFrame.cpp index 98582b48228..323588e67fd 100644 --- a/mozilla/layout/generic/nsImageFrame.cpp +++ b/mozilla/layout/generic/nsImageFrame.cpp @@ -48,6 +48,7 @@ #include "nsHTMLAtoms.h" #include "nsIDocument.h" #include "nsINodeInfo.h" +#include "nsContentUtils.h" #include "nsStyleContext.h" #include "nsStyleConsts.h" #include "nsImageMap.h" @@ -92,7 +93,6 @@ #include "nsIDOMWindow.h" #include "nsIDOMDocument.h" #include "nsCSSFrameConstructor.h" -#include "nsIPrefBranch.h" #include "nsIPrefBranchInternal.h" #include "nsIPrefService.h" #include "gfxIImageFrame.h" @@ -1944,15 +1944,14 @@ nsImageFrame::IconLoad::IconLoad(imgIDecoderObserver *aObserver) : mLoadObserver(aObserver), mIconsLoaded(0) { - nsCOMPtr prefService = - do_GetService(NS_PREFSERVICE_CONTRACTID); + nsCOMPtr prefBranch = + do_QueryInterface(nsContentUtils::GetPrefBranch()); // register observers - nsCOMPtr pbi = do_QueryInterface(prefService); for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(kIconLoadPrefs); ++i) - pbi->AddObserver(kIconLoadPrefs[i], this, PR_FALSE); + prefBranch->AddObserver(kIconLoadPrefs[i], this, PR_FALSE); - GetPrefs(prefService); + GetPrefs(); } @@ -1970,32 +1969,21 @@ nsImageFrame::IconLoad::Observe(nsISupports *aSubject, const char* aTopic, break; #endif - nsCOMPtr prefService = do_QueryInterface(aSubject); - GetPrefs(prefService); + GetPrefs(); return NS_OK; } -void nsImageFrame::IconLoad::GetPrefs(nsIPrefBranch *aPrefService) +void nsImageFrame::IconLoad::GetPrefs() { - if (aPrefService) { - PRBool boolPref; - PRInt32 intPref; - if (NS_SUCCEEDED(aPrefService->GetBoolPref("browser.display.force_inline_alttext", &boolPref))) { - mPrefForceInlineAltText = boolPref; - } else { - mPrefForceInlineAltText = PR_FALSE; - } - if (NS_SUCCEEDED(aPrefService->GetIntPref("network.image.imageBehavior", &intPref)) && intPref == 2) { - mPrefAllImagesBlocked = PR_TRUE; - } else { - mPrefAllImagesBlocked = PR_FALSE; - } - if (NS_SUCCEEDED(aPrefService->GetBoolPref("browser.display.show_image_placeholders", &boolPref))) { - mPrefShowPlaceholders = boolPref; - } else { - mPrefShowPlaceholders = PR_TRUE; - } - } + mPrefForceInlineAltText = + nsContentUtils::GetBoolPref("browser.display.force_inline_alttext"); + + mPrefAllImagesBlocked = + nsContentUtils::GetIntPref("network.image.imageBehavior") == 2; + + mPrefShowPlaceholders = + nsContentUtils::GetBoolPref("browser.display.show_image_placeholders", + PR_TRUE); } NS_IMPL_ISUPPORTS2(nsImageListener, imgIDecoderObserver, imgIContainerObserver) diff --git a/mozilla/layout/generic/nsImageFrame.h b/mozilla/layout/generic/nsImageFrame.h index 5ca4909fb74..b1f8406ceb5 100644 --- a/mozilla/layout/generic/nsImageFrame.h +++ b/mozilla/layout/generic/nsImageFrame.h @@ -57,7 +57,6 @@ class nsILoadGroup; struct nsHTMLReflowState; struct nsHTMLReflowMetrics; struct nsSize; -class nsIPrefBranch; class nsImageFrame; @@ -296,7 +295,7 @@ private: NS_DECL_NSIOBSERVER private: - void GetPrefs(nsIPrefBranch *aPrefService); + void GetPrefs(); public: nsCOMPtr mLoadingImage; diff --git a/mozilla/layout/generic/nsObjectFrame.cpp b/mozilla/layout/generic/nsObjectFrame.cpp index d98af91feea..848c4842b23 100644 --- a/mozilla/layout/generic/nsObjectFrame.cpp +++ b/mozilla/layout/generic/nsObjectFrame.cpp @@ -119,10 +119,6 @@ #include "nsIClassInfo.h" #include "jsapi.h" -// XXX temporary for Mac double buffering pref -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" - // XXX For temporary paint code #include "nsStyleContext.h" @@ -801,11 +797,8 @@ 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)); - PRBool doubleBuffer = PR_FALSE; - if (prefBranch) { - prefBranch->GetBoolPref("plugin.enable_double_buffer", &doubleBuffer); - } + PRBool doubleBuffer = + nsContentUtils::GetBoolPref("plugin.enable_double_buffer"); viewMan->AllowDoubleBuffering(doubleBuffer); #endif diff --git a/mozilla/layout/generic/nsSelection.cpp b/mozilla/layout/generic/nsSelection.cpp index 26ba2b82f4a..838100bfbbe 100644 --- a/mozilla/layout/generic/nsSelection.cpp +++ b/mozilla/layout/generic/nsSelection.cpp @@ -68,8 +68,6 @@ #include "nsISelectionListener.h" #include "nsIContentIterator.h" #include "nsIDocumentEncoder.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" // for IBMBIDI #include "nsFrameTraversal.h" @@ -929,24 +927,17 @@ nsSelection::nsSelection() mSelectingTableCellMode = 0; mSelectedCellIndex = 0; - - // Check to see if the autocopy pref is enabled // and add the autocopy listener if it is - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - static char pref[] = "clipboard.autocopy"; - PRBool autoCopy = PR_FALSE; - if (NS_SUCCEEDED(prefBranch->GetBoolPref(pref, &autoCopy)) && autoCopy) { - nsCOMPtr autoCopyService = - do_GetService("@mozilla.org/autocopy;1"); + if (nsContentUtils::GetBoolPref("clipboard.autocopy")) { + nsCOMPtr autoCopyService = + do_GetService("@mozilla.org/autocopy;1"); - if (autoCopyService) { - PRInt8 index = - GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); - if (mDomSelections[index]) { - autoCopyService->Listen(mDomSelections[index]); - } + if (autoCopyService) { + PRInt8 index = + GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL); + if (mDomSelections[index]) { + autoCopyService->Listen(mDomSelections[index]); } } } diff --git a/mozilla/layout/generic/nsSimplePageSequence.cpp b/mozilla/layout/generic/nsSimplePageSequence.cpp index 8eb88418458..3fab24094fa 100644 --- a/mozilla/layout/generic/nsSimplePageSequence.cpp +++ b/mozilla/layout/generic/nsSimplePageSequence.cpp @@ -52,10 +52,7 @@ #include "nsRegion.h" #include "nsLayoutAtoms.h" #include "nsCSSFrameConstructor.h" - -// for header/footer gap & ExtraMargin for Print Preview -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" +#include "nsContentUtils.h" // DateTime Includes #include "nsDateTimeFormatCID.h" @@ -298,18 +295,14 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext, nsRect adjSize; aPresContext->GetPageDim(&pageSize, &adjSize); - nscoord extraGap = 0; - nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); - if (prefBranch) { - GetEdgePaperMargin(mPageData->mEdgePaperMargin); - nscoord extraThreshold = PR_MAX(pageSize.width, pageSize.height)/10; - PRInt32 gapInTwips; - if (NS_SUCCEEDED(prefBranch->GetIntPref("print.print_extra_margin", &gapInTwips))) { - gapInTwips = PR_MAX(gapInTwips, 0); - gapInTwips = PR_MIN(gapInTwips, extraThreshold); // clamp to 1/10 of the largest dim of the page - extraGap = nscoord(gapInTwips); - } - } + GetEdgePaperMargin(mPageData->mEdgePaperMargin); + nscoord extraThreshold = PR_MAX(pageSize.width, pageSize.height)/10; + PRInt32 gapInTwips = nsContentUtils::GetIntPref("print.print_extra_margin"); + + gapInTwips = PR_MAX(gapInTwips, 0); + gapInTwips = PR_MIN(gapInTwips, extraThreshold); // clamp to 1/10 of the largest dim of the page + + nscoord extraGap = nscoord(gapInTwips); nscoord deadSpaceGap; GetDeadSpaceValue(&deadSpaceGap); diff --git a/mozilla/layout/generic/nsTextFrame.cpp b/mozilla/layout/generic/nsTextFrame.cpp index 82f6dba5316..71d985f6e79 100644 --- a/mozilla/layout/generic/nsTextFrame.cpp +++ b/mozilla/layout/generic/nsTextFrame.cpp @@ -1,3 +1,4 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * @@ -80,13 +81,12 @@ #include "nsIDOMRange.h" #include "nsILookAndFeel.h" #include "nsCSSRendering.h" +#include "nsContentUtils.h" #include "nsILineIterator.h" #include "nsCompressedCharMap.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" #include "nsIServiceManager.h" #ifdef ACCESSIBILITY #include "nsIAccessible.h" @@ -961,8 +961,8 @@ private: PRUnichar *mUniStr; char *mCStr; }; - PRUint32 mLength; - PRUint32 mCurrentIdx; + PRUint32 mLength; + PRUint32 mCurrentIdx; PRUint32 mCurrentLength; nsTextFrame::TextStyle &mOldStyle;//base new styles on this one??? const SelectionDetails *mDetails; @@ -1004,8 +1004,8 @@ DrawSelectionIterator::DrawSelectionIterator(nsIContent *aContent, if (aContent) { nsRefPtr sc; sc = aPresContext->StyleSet()-> - ProbePseudoStyleFor(aContent->GetParent(), - nsCSSPseudoElements::mozSelection, aStyleContext); + ProbePseudoStyleFor(aContent->GetParent(), + nsCSSPseudoElements::mozSelection, aStyleContext); if (sc) { mSelectionPseudoStyle = PR_TRUE; const nsStyleBackground* bg = sc->GetStyleBackground(); @@ -1062,12 +1062,12 @@ DrawSelectionIterator::DrawSelectionIterator(nsIContent *aContent, } details= details->mNext; } - if (!mInit && mTypes) //we have details but none that we care about. - { - delete mTypes; - mTypes = nsnull; - mDone = PR_TRUE;//we are finished - } + if (!mInit && mTypes) //we have details but none that we care about. + { + delete mTypes; + mTypes = nsnull; + mDone = PR_TRUE;//we are finished + } } else if (details->mStart == details->mEnd)//no collapsed selections here! { @@ -1203,7 +1203,7 @@ DrawSelectionIterator::CurrentForeGroundColor() else if (mTypes[mCurrentIdx] | nsISelectionController::SELECTION_NORMAL)//Find color based on mTypes[mCurrentIdx]; { foreColor = mOldStyle.mSelectionTextColor; - colorSet = PR_TRUE; + colorSet = PR_TRUE; } if (colorSet && (foreColor != NS_DONT_CHANGE_COLOR)) { @@ -1305,12 +1305,9 @@ nsTextFrame::nsTextFrame() { // read in our global word selection prefs if ( !sWordSelectPrefInited ) { - nsCOMPtr prefBranch ( do_GetService(NS_PREFSERVICE_CONTRACTID) ); - if ( prefBranch ) { - PRBool temp = PR_FALSE; - prefBranch->GetBoolPref("layout.word_select.eat_space_to_next_word", &temp); - sWordSelectEatSpaceAfter = temp; - } + sWordSelectEatSpaceAfter = + nsContentUtils::GetBoolPref("layout.word_select.eat_space_to_next_word"); + sWordSelectPrefInited = PR_TRUE; } } @@ -1565,7 +1562,7 @@ nsTextFrame::PrepareUnicodeText(nsTextTransformer& aTX, // XXX This is a one to many mapping that I think isn't handled well if (nsnull != indexp) { *indexp++ = strInx; - strInx += wordLen; + strInx += wordLen; } } else if ('\n' == bp[0]) { @@ -1681,7 +1678,7 @@ nsTextFrame::PrepareUnicodeText(nsTextTransformer& aTX, } -//#define SHOW_SELECTION_CURSOR // should be turned off when the caret code is activated +//#define SHOW_SELECTION_CURSOR // should be turned off when the caret code is activated #ifdef SHOW_SELECTION_CURSOR @@ -1905,7 +1902,7 @@ nsTextFrame::PaintTextDecorations(nsIRenderingContext& aRenderingContext, aRenderingContext.SetColor(NS_RGB(255,255,128)); aRenderingContext.DrawRect(aX + startOffset, aY, textWidth, rect.height); #endif - aTextStyle.mNormalFont->GetUnderline(offset, size); + aTextStyle.mNormalFont->GetUnderline(offset, size); aRenderingContext.SetColor(IME_CONVERTED_COLOR); aRenderingContext.FillRect(aX + startOffset+size, aY + baseline - offset, textWidth-2*size, size); }break; @@ -1952,7 +1949,7 @@ nsTextFrame::GetContentAndOffsetsForSelection(nsIPresContext *aPresContext, nsIC nsIFrame *grandParent = parent->GetParent(); if (grandParent) { - nsIFrame *firstParent = grandParent->GetFirstChild(nsnull); + nsIFrame *firstParent = grandParent->GetFirstChild(nsnull); if (firstParent) { *aLength = 0; @@ -2392,7 +2389,7 @@ nsTextFrame::PaintUnicodeText(nsIPresContext* aPresContext, #ifdef IBMBIDI if (!isRightToLeftOnBidiPlatform) #endif - currentX+=newWidth;//increment twips X start + currentX += newWidth; // increment twips X start iter.Next(); } @@ -2517,23 +2514,22 @@ 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) ); - PRInt32 prefInt = 0; + PRInt32 prefInt = + nsContentUtils::GetIntPref("browser.drag_out_of_frame_style"); + PRBool outofstylehandled = PR_FALSE; - if (prefBranch) - { - if (NS_SUCCEEDED(prefBranch->GetIntPref("browser.drag_out_of_frame_style", &prefInt)) && prefInt) + + if (prefInt) + { + if (aPoint.y < origin.y)//above rectangle { - if (aPoint.y < origin.y)//above rectangle - { - aOffset = mContentOffset; - outofstylehandled = PR_TRUE; - } - else if ((aPoint.y - origin.y) > mRect.height) - { - aOffset = mContentOffset + mContentLength; - outofstylehandled = PR_TRUE; - } + aOffset = mContentOffset; + outofstylehandled = PR_TRUE; + } + else if ((aPoint.y - origin.y) > mRect.height) + { + aOffset = mContentOffset + mContentLength; + outofstylehandled = PR_TRUE; } } @@ -2995,19 +2991,19 @@ nsTextFrame::PaintTextSlowly(nsIPresContext* aPresContext, DrawSelectionIterator iter(content, details,text,(PRUint32)textLength,aTextStyle, selectionValue, aPresContext, mStyleContext); if (!iter.IsDone() && iter.First()) { - nscoord currentX = dx; - nsTextDimensions newDimensions;//temp - while (!iter.IsDone()) - { - PRUnichar *currenttext = iter.CurrentTextUnicharPtr(); - PRUint32 currentlength= iter.CurrentLength(); - //TextStyle ¤tStyle = iter.CurrentStyle(); - nscolor currentFGColor = iter.CurrentForeGroundColor(); - nscolor currentBKColor; - PRBool isCurrentBKColorTransparent; - GetTextDimensions(aRenderingContext,aTextStyle,currenttext, (PRInt32)currentlength,&newDimensions); - if (newDimensions.width) - { + nscoord currentX = dx; + nsTextDimensions newDimensions;//temp + while (!iter.IsDone()) + { + PRUnichar *currenttext = iter.CurrentTextUnicharPtr(); + PRUint32 currentlength= iter.CurrentLength(); + //TextStyle ¤tStyle = iter.CurrentStyle(); + nscolor currentFGColor = iter.CurrentForeGroundColor(); + nscolor currentBKColor; + PRBool isCurrentBKColorTransparent; + GetTextDimensions(aRenderingContext,aTextStyle,currenttext, (PRInt32)currentlength,&newDimensions); + if (newDimensions.width) + { if (iter.CurrentBackGroundColor(currentBKColor, &isCurrentBKColorTransparent)) {//DRAW RECT HERE!!! if (!isCurrentBKColorTransparent) { @@ -3016,25 +3012,26 @@ nsTextFrame::PaintTextSlowly(nsIPresContext* aPresContext, } currentFGColor = EnsureDifferentColors(currentFGColor, currentBKColor); } - } + } - if (isPaginated && !iter.IsBeforeOrAfter()) { - aRenderingContext.SetColor(nsCSSRendering::TransformColor(aTextStyle.mColor->mColor,canDarkenColor)); - RenderString(aRenderingContext, aStyleContext, aPresContext, - aTextStyle, currenttext, currentlength, - currentX, dy, width, details); - } else if (!isPaginated) { - aRenderingContext.SetColor(nsCSSRendering::TransformColor(currentFGColor,canDarkenColor)); - RenderString(aRenderingContext,aStyleContext, aPresContext, - aTextStyle, currenttext, currentlength, currentX, - dy, width, details); + if (isPaginated && !iter.IsBeforeOrAfter()) { + aRenderingContext.SetColor(nsCSSRendering::TransformColor(aTextStyle.mColor->mColor, canDarkenColor)); + RenderString(aRenderingContext, aStyleContext, aPresContext, + aTextStyle, currenttext, currentlength, + currentX, dy, width, details); + } else if (!isPaginated) { + aRenderingContext.SetColor(nsCSSRendering::TransformColor(currentFGColor, canDarkenColor)); + RenderString(aRenderingContext,aStyleContext, aPresContext, + aTextStyle, currenttext, currentlength, currentX, + dy, width, details); + } + + // increment twips X start but remember to get ready for + // next draw by reducing current x by letter spacing amount + currentX += newDimensions.width; // + aTextStyle.mLetterSpacing; + + iter.Next(); } - - //increment twips X start but remember to get ready for next draw by reducing current x by letter spacing amount - currentX+=newDimensions.width;// + aTextStyle.mLetterSpacing; - - iter.Next(); - } } else if (!isPaginated) { @@ -3393,25 +3390,23 @@ 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) ); - PRInt32 prefInt = 0; + PRInt32 prefInt = + nsContentUtils::GetIntPref("browser.drag_out_of_frame_style"); PRBool outofstylehandled = PR_FALSE; - if (prefBranch) - { - if (NS_SUCCEEDED(prefBranch->GetIntPref("browser.drag_out_of_frame_style", &prefInt)) && prefInt) + + if (prefInt) + { + if ((aPoint.y - origin.y) < 0)//above rectangle { - if ((aPoint.y - origin.y) < 0)//above rectangle - { - aContentOffset = mContentOffset; - aContentOffsetEnd = aContentOffset; - outofstylehandled = PR_TRUE; - } - else if ((aPoint.y - origin.y) > mRect.height) - { - aContentOffset = mContentOffset + mContentLength; - aContentOffsetEnd = aContentOffset; - outofstylehandled = PR_TRUE; - } + aContentOffset = mContentOffset; + aContentOffsetEnd = aContentOffset; + outofstylehandled = PR_TRUE; + } + else if ((aPoint.y - origin.y) > mRect.height) + { + aContentOffset = mContentOffset + mContentLength; + aContentOffsetEnd = aContentOffset; + outofstylehandled = PR_TRUE; } } @@ -3613,7 +3608,7 @@ nsTextFrame::SetSelected(nsIPresContext* aPresContext, if (shell) { nsCOMPtr selCon; nsresult rv = GetSelectionController(aPresContext, - getter_AddRefs(selCon)); + getter_AddRefs(selCon)); if (NS_SUCCEEDED(rv) && selCon) { frameSelection = do_QueryInterface(selCon); //this MAY implement diff --git a/mozilla/layout/generic/nsTextTransformer.cpp b/mozilla/layout/generic/nsTextTransformer.cpp index b3b442a2ab0..98565e03393 100644 --- a/mozilla/layout/generic/nsTextTransformer.cpp +++ b/mozilla/layout/generic/nsTextTransformer.cpp @@ -37,6 +37,7 @@ #include #include "nsCOMPtr.h" #include "nsTextTransformer.h" +#include "nsContentUtils.h" #include "nsIContent.h" #include "nsIFrame.h" #include "nsITextContent.h" @@ -48,29 +49,22 @@ #include "nsUnicharUtils.h" #include "nsICaseConversion.h" #include "prenv.h" -#include "nsIPrefBranchInternal.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" #ifdef IBMBIDI #include "nsLayoutAtoms.h" #endif -nsTextTransformer::WordSelectListener *nsTextTransformer::sWordSelectListener = nsnull; +PRBool nsTextTransformer::sWordSelectListenerPrefChecked = PR_FALSE; PRBool nsTextTransformer::sWordSelectStopAtPunctuation = PR_FALSE; static const char kWordSelectPref[] = "layout.word_select.stop_at_punctuation"; -NS_IMPL_ISUPPORTS1(nsTextTransformer::WordSelectListener, nsIObserver) - -NS_IMETHODIMP -nsTextTransformer::WordSelectListener::Observe(nsISupports *aSubject, - const char *aTopic, - const PRUnichar *aData) +// static +int +nsTextTransformer::WordSelectPrefCallback(const char* aPref, void* aClosure) { - NS_ASSERTION(!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID), - "wrong topic"); - nsCOMPtr prefBranch = do_QueryInterface(aSubject); - return prefBranch->GetBoolPref(kWordSelectPref, &sWordSelectStopAtPunctuation); + sWordSelectStopAtPunctuation = nsContentUtils::GetBoolPref(kWordSelectPref); + + return 0; } nsAutoTextBuffer::nsAutoTextBuffer() @@ -125,17 +119,14 @@ nsresult nsTextTransformer::Initialize() { // read in our global word selection prefs - if ( !sWordSelectListener ) { - nsCOMPtr prefBranch = - do_GetService( NS_PREFSERVICE_CONTRACTID ); - if ( prefBranch ) { - prefBranch->GetBoolPref(kWordSelectPref, &sWordSelectStopAtPunctuation); - sWordSelectListener = new WordSelectListener(); - if (sWordSelectListener) { - NS_ADDREF(sWordSelectListener); - prefBranch->AddObserver(kWordSelectPref, sWordSelectListener, PR_FALSE); - } - } + if ( !sWordSelectListenerPrefChecked ) { + sWordSelectListenerPrefChecked = PR_TRUE; + + sWordSelectStopAtPunctuation = + nsContentUtils::GetBoolPref(kWordSelectPref); + + nsContentUtils::RegisterPrefCallback(kWordSelectPref, + WordSelectPrefCallback, nsnull); } return NS_OK; @@ -155,7 +146,6 @@ static nsresult EnsureCaseConv() void nsTextTransformer::Shutdown() { - NS_IF_RELEASE(sWordSelectListener); if (gCaseConv) { nsServiceManager::ReleaseService(kUnicharUtilCID, gCaseConv); gCaseConv = nsnull; diff --git a/mozilla/layout/generic/nsTextTransformer.h b/mozilla/layout/generic/nsTextTransformer.h index 9b90dddb277..591499ab225 100644 --- a/mozilla/layout/generic/nsTextTransformer.h +++ b/mozilla/layout/generic/nsTextTransformer.h @@ -349,14 +349,9 @@ protected: PRUint8 mFlags; // prefs used to configure the double-click word selection behavior - class WordSelectListener: public nsIObserver { - public: - NS_DECL_ISUPPORTS - NS_DECL_NSIOBSERVER - }; - friend class WordSelectListener; - static WordSelectListener *sWordSelectListener; // have we read the prefs yet? - static PRBool sWordSelectStopAtPunctuation; // should we stop at punctuation? + static int WordSelectPrefCallback(const char* aPref, void* aClosure); + static PRBool sWordSelectListenerPrefChecked; // have we read the prefs yet? + static PRBool sWordSelectStopAtPunctuation; // should we stop at punctuation? #ifdef DEBUG static void SelfTest(nsILineBreaker* aLineBreaker, diff --git a/mozilla/layout/html/base/src/nsFrame.cpp b/mozilla/layout/html/base/src/nsFrame.cpp index f35c6c1e054..ea72eaff02e 100644 --- a/mozilla/layout/html/base/src/nsFrame.cpp +++ b/mozilla/layout/html/base/src/nsFrame.cpp @@ -41,6 +41,7 @@ #include "nsFrameList.h" #include "nsLineLayout.h" #include "nsIContent.h" +#include "nsContentUtils.h" #include "nsIAtom.h" #include "nsString.h" #include "nsReadableUtils.h" @@ -92,8 +93,6 @@ #include "nsIPercentHeightObserver.h" // For triple-click pref -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" #include "nsIServiceManager.h" #include "nsISelectionImageService.h" #include "imgIContainer.h" @@ -1610,9 +1609,8 @@ 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); + selectPara = + nsContentUtils::GetBoolPref("browser.triple_click_selects_paragraph"); } else return NS_OK; diff --git a/mozilla/layout/html/base/src/nsHTMLReflowState.cpp b/mozilla/layout/html/base/src/nsHTMLReflowState.cpp index 876c362b0ec..1f7b9e5999f 100644 --- a/mozilla/layout/html/base/src/nsHTMLReflowState.cpp +++ b/mozilla/layout/html/base/src/nsHTMLReflowState.cpp @@ -49,9 +49,9 @@ #include "nsBlockFrame.h" #include "nsLineBox.h" #include "nsImageFrame.h" -#include "nsIPref.h" #include "nsIServiceManager.h" #include "nsIPercentHeightObserver.h" +#include "nsContentUtils.h" #ifdef IBMBIDI #include "nsBidiUtils.h" #endif @@ -1519,14 +1519,12 @@ nsHTMLReflowState::ComputeContainingBlockRectangle(nsIPresContext* aPre } // Prefs callback to pick up changes -static int PR_CALLBACK PrefsChanged(const char *aPrefName, void *instance) +PR_STATIC_CALLBACK(int) +PrefsChanged(const char *aPrefName, void *instance) { - nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID); - if (prefs) { - PRBool boolPref; - if (NS_SUCCEEDED(prefs->GetBoolPref("browser.blink_allowed", &boolPref))) - sBlinkIsAllowed = boolPref; - } + sBlinkIsAllowed = + nsContentUtils::GetBoolPref("browser.blink_allowed", sBlinkIsAllowed); + return 0; /* PREF_OK */ } @@ -1537,11 +1535,8 @@ static PRBool BlinkIsAllowed(void) { if (!sPrefIsLoaded) { // Set up a listener and check the initial value - nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID); - if (prefs) { - prefs->RegisterCallback("browser.blink_allowed", PrefsChanged, - nsnull); - } + nsContentUtils::RegisterPrefCallback("browser.blink_allowed", PrefsChanged, + nsnull); PrefsChanged(nsnull, nsnull); sPrefIsLoaded = PR_TRUE; } @@ -1552,15 +1547,11 @@ static PRBool BlinkIsAllowed(void) static eNormalLineHeightControl GetNormalLineHeightCalcControl(void) { if (sNormalLineHeightControl == eUninitialized) { - 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 (prefs && NS_SUCCEEDED(prefs->GetIntPref( - "browser.display.normal_lineheight_calc_control", &intPref))) - sNormalLineHeightControl = NS_STATIC_CAST(eNormalLineHeightControl, intPref); - else - sNormalLineHeightControl = eNoExternalLeading; + // browser.display.normal_lineheight_calc_control is not user + // changable, so no need to register callback for it. + sNormalLineHeightControl = + NS_STATIC_CAST(eNormalLineHeightControl, + nsContentUtils::GetIntPref("browser.display.normal_lineheight_calc_control", eNoExternalLeading)); } return sNormalLineHeightControl; } diff --git a/mozilla/layout/html/base/src/nsImageFrame.cpp b/mozilla/layout/html/base/src/nsImageFrame.cpp index 98582b48228..323588e67fd 100644 --- a/mozilla/layout/html/base/src/nsImageFrame.cpp +++ b/mozilla/layout/html/base/src/nsImageFrame.cpp @@ -48,6 +48,7 @@ #include "nsHTMLAtoms.h" #include "nsIDocument.h" #include "nsINodeInfo.h" +#include "nsContentUtils.h" #include "nsStyleContext.h" #include "nsStyleConsts.h" #include "nsImageMap.h" @@ -92,7 +93,6 @@ #include "nsIDOMWindow.h" #include "nsIDOMDocument.h" #include "nsCSSFrameConstructor.h" -#include "nsIPrefBranch.h" #include "nsIPrefBranchInternal.h" #include "nsIPrefService.h" #include "gfxIImageFrame.h" @@ -1944,15 +1944,14 @@ nsImageFrame::IconLoad::IconLoad(imgIDecoderObserver *aObserver) : mLoadObserver(aObserver), mIconsLoaded(0) { - nsCOMPtr prefService = - do_GetService(NS_PREFSERVICE_CONTRACTID); + nsCOMPtr prefBranch = + do_QueryInterface(nsContentUtils::GetPrefBranch()); // register observers - nsCOMPtr pbi = do_QueryInterface(prefService); for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(kIconLoadPrefs); ++i) - pbi->AddObserver(kIconLoadPrefs[i], this, PR_FALSE); + prefBranch->AddObserver(kIconLoadPrefs[i], this, PR_FALSE); - GetPrefs(prefService); + GetPrefs(); } @@ -1970,32 +1969,21 @@ nsImageFrame::IconLoad::Observe(nsISupports *aSubject, const char* aTopic, break; #endif - nsCOMPtr prefService = do_QueryInterface(aSubject); - GetPrefs(prefService); + GetPrefs(); return NS_OK; } -void nsImageFrame::IconLoad::GetPrefs(nsIPrefBranch *aPrefService) +void nsImageFrame::IconLoad::GetPrefs() { - if (aPrefService) { - PRBool boolPref; - PRInt32 intPref; - if (NS_SUCCEEDED(aPrefService->GetBoolPref("browser.display.force_inline_alttext", &boolPref))) { - mPrefForceInlineAltText = boolPref; - } else { - mPrefForceInlineAltText = PR_FALSE; - } - if (NS_SUCCEEDED(aPrefService->GetIntPref("network.image.imageBehavior", &intPref)) && intPref == 2) { - mPrefAllImagesBlocked = PR_TRUE; - } else { - mPrefAllImagesBlocked = PR_FALSE; - } - if (NS_SUCCEEDED(aPrefService->GetBoolPref("browser.display.show_image_placeholders", &boolPref))) { - mPrefShowPlaceholders = boolPref; - } else { - mPrefShowPlaceholders = PR_TRUE; - } - } + mPrefForceInlineAltText = + nsContentUtils::GetBoolPref("browser.display.force_inline_alttext"); + + mPrefAllImagesBlocked = + nsContentUtils::GetIntPref("network.image.imageBehavior") == 2; + + mPrefShowPlaceholders = + nsContentUtils::GetBoolPref("browser.display.show_image_placeholders", + PR_TRUE); } NS_IMPL_ISUPPORTS2(nsImageListener, imgIDecoderObserver, imgIContainerObserver) diff --git a/mozilla/layout/html/base/src/nsImageFrame.h b/mozilla/layout/html/base/src/nsImageFrame.h index 5ca4909fb74..b1f8406ceb5 100644 --- a/mozilla/layout/html/base/src/nsImageFrame.h +++ b/mozilla/layout/html/base/src/nsImageFrame.h @@ -57,7 +57,6 @@ class nsILoadGroup; struct nsHTMLReflowState; struct nsHTMLReflowMetrics; struct nsSize; -class nsIPrefBranch; class nsImageFrame; @@ -296,7 +295,7 @@ private: NS_DECL_NSIOBSERVER private: - void GetPrefs(nsIPrefBranch *aPrefService); + void GetPrefs(); public: nsCOMPtr mLoadingImage; diff --git a/mozilla/layout/html/base/src/nsObjectFrame.cpp b/mozilla/layout/html/base/src/nsObjectFrame.cpp index d98af91feea..848c4842b23 100644 --- a/mozilla/layout/html/base/src/nsObjectFrame.cpp +++ b/mozilla/layout/html/base/src/nsObjectFrame.cpp @@ -119,10 +119,6 @@ #include "nsIClassInfo.h" #include "jsapi.h" -// XXX temporary for Mac double buffering pref -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" - // XXX For temporary paint code #include "nsStyleContext.h" @@ -801,11 +797,8 @@ 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)); - PRBool doubleBuffer = PR_FALSE; - if (prefBranch) { - prefBranch->GetBoolPref("plugin.enable_double_buffer", &doubleBuffer); - } + PRBool doubleBuffer = + nsContentUtils::GetBoolPref("plugin.enable_double_buffer"); viewMan->AllowDoubleBuffering(doubleBuffer); #endif diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index 8f8d877e858..d963f39b235 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -74,8 +74,6 @@ #include "prinrval.h" #include "nsVoidArray.h" #include "nsHashtable.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" #include "nsIViewObserver.h" #include "nsContainerFrame.h" #include "nsIDeviceContext.h" @@ -83,6 +81,7 @@ #include "nsIDOMEvent.h" #include "nsGUIEvent.h" #include "nsHTMLParts.h" +#include "nsContentUtils.h" #include "nsISelection.h" #include "nsISelectionController.h" #include "nsReflowPath.h" @@ -1774,17 +1773,13 @@ PresShell::Init(nsIDocument* aDocument, } if (gMaxRCProcessingTime == -1) { - // First, set the defaults - gMaxRCProcessingTime = NS_MAX_REFLOW_TIME; - gAsyncReflowDuringDocLoad = PR_TRUE; + gMaxRCProcessingTime = + nsContentUtils::GetIntPref("layout.reflow.timeslice", + NS_MAX_REFLOW_TIME); - // 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); - } + gAsyncReflowDuringDocLoad = + nsContentUtils::GetBoolPref("layout.reflow.async.duringDocLoad", + PR_TRUE); } // cache the observation service @@ -1804,23 +1799,18 @@ PresShell::Init(nsIDocument* aDocument, #ifdef MOZ_REFLOW_PERF if (mReflowCountMgr) { - // Get the prefs service - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - PRBool paintFrameCounts = PR_FALSE; - PRBool dumpFrameCounts = PR_FALSE; - PRBool dumpFrameByFrameCounts = PR_FALSE; - prefBranch->GetBoolPref("layout.reflow.showframecounts", - &paintFrameCounts); - prefBranch->GetBoolPref("layout.reflow.dumpframecounts", - &dumpFrameCounts); - prefBranch->GetBoolPref("layout.reflow.dumpframebyframecounts", - &dumpFrameByFrameCounts); + PRBool paintFrameCounts = + nsContentUtils::GetBoolPref("layout.reflow.showframecounts"); - mReflowCountMgr->SetDumpFrameCounts(dumpFrameCounts); - mReflowCountMgr->SetDumpFrameByFrameCounts(dumpFrameByFrameCounts); - mReflowCountMgr->SetPaintFrameCounts(paintFrameCounts); - } + PRBool dumpFrameCounts = + nsContentUtils::GetBoolPref("layout.reflow.dumpframecounts"); + + PRBool dumpFrameByFrameCounts = + nsContentUtils::GetBoolPref("layout.reflow.dumpframebyframecounts"); + + mReflowCountMgr->SetDumpFrameCounts(dumpFrameCounts); + mReflowCountMgr->SetDumpFrameByFrameCounts(dumpFrameByFrameCounts); + mReflowCountMgr->SetPaintFrameCounts(paintFrameCounts); } #endif @@ -2892,15 +2882,17 @@ PresShell::InitialReflow(nscoord aWidth, nscoord aHeight) mPaintingSuppressed = PR_FALSE; 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); + + // Default to PAINTLOCK_EVENT_DELAY if we can't get the pref value. + PRInt32 delay = + nsContentUtils::GetIntPref("nglayout.initialpaint.delay", + PAINTLOCK_EVENT_DELAY); nsCOMPtr ti = do_QueryInterface(mPaintSuppressionTimer); ti->SetIdle(PR_FALSE); - mPaintSuppressionTimer->InitWithFuncCallback(sPaintSuppressionCallback, this, delay, + mPaintSuppressionTimer->InitWithFuncCallback(sPaintSuppressionCallback, + this, delay, nsITimer::TYPE_ONE_SHOT); } } @@ -4059,15 +4051,14 @@ PresShell::GoToAnchor(const nsAString& aAnchorName, PRBool aScroll) NS_PRESSHELL_SCROLL_ANYWHERE); if (NS_SUCCEEDED(rv)) { - // 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); - } - // Even if select anchor pref is false, we must still move the caret there. - // That way tabbing will start from the new location + // Should we select the target? This action is controlled by a + // preference: the default is to not select. + PRBool selectAnchor = + nsContentUtils::GetBoolPref("layout.selectanchor"); + + // Even if select anchor pref is false, we must still move the + // caret there. That way tabbing will start from the new + // location if (!jumpToRange) { jumpToRange = do_CreateInstance(kRangeCID); nsCOMPtr node(do_QueryInterface(content)); diff --git a/mozilla/layout/html/base/src/nsSimplePageSequence.cpp b/mozilla/layout/html/base/src/nsSimplePageSequence.cpp index 8eb88418458..3fab24094fa 100644 --- a/mozilla/layout/html/base/src/nsSimplePageSequence.cpp +++ b/mozilla/layout/html/base/src/nsSimplePageSequence.cpp @@ -52,10 +52,7 @@ #include "nsRegion.h" #include "nsLayoutAtoms.h" #include "nsCSSFrameConstructor.h" - -// for header/footer gap & ExtraMargin for Print Preview -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" +#include "nsContentUtils.h" // DateTime Includes #include "nsDateTimeFormatCID.h" @@ -298,18 +295,14 @@ nsSimplePageSequenceFrame::Reflow(nsIPresContext* aPresContext, nsRect adjSize; aPresContext->GetPageDim(&pageSize, &adjSize); - nscoord extraGap = 0; - nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); - if (prefBranch) { - GetEdgePaperMargin(mPageData->mEdgePaperMargin); - nscoord extraThreshold = PR_MAX(pageSize.width, pageSize.height)/10; - PRInt32 gapInTwips; - if (NS_SUCCEEDED(prefBranch->GetIntPref("print.print_extra_margin", &gapInTwips))) { - gapInTwips = PR_MAX(gapInTwips, 0); - gapInTwips = PR_MIN(gapInTwips, extraThreshold); // clamp to 1/10 of the largest dim of the page - extraGap = nscoord(gapInTwips); - } - } + GetEdgePaperMargin(mPageData->mEdgePaperMargin); + nscoord extraThreshold = PR_MAX(pageSize.width, pageSize.height)/10; + PRInt32 gapInTwips = nsContentUtils::GetIntPref("print.print_extra_margin"); + + gapInTwips = PR_MAX(gapInTwips, 0); + gapInTwips = PR_MIN(gapInTwips, extraThreshold); // clamp to 1/10 of the largest dim of the page + + nscoord extraGap = nscoord(gapInTwips); nscoord deadSpaceGap; GetDeadSpaceValue(&deadSpaceGap); diff --git a/mozilla/layout/html/base/src/nsTextFrame.cpp b/mozilla/layout/html/base/src/nsTextFrame.cpp index 82f6dba5316..71d985f6e79 100644 --- a/mozilla/layout/html/base/src/nsTextFrame.cpp +++ b/mozilla/layout/html/base/src/nsTextFrame.cpp @@ -1,3 +1,4 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * @@ -80,13 +81,12 @@ #include "nsIDOMRange.h" #include "nsILookAndFeel.h" #include "nsCSSRendering.h" +#include "nsContentUtils.h" #include "nsILineIterator.h" #include "nsCompressedCharMap.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" #include "nsIServiceManager.h" #ifdef ACCESSIBILITY #include "nsIAccessible.h" @@ -961,8 +961,8 @@ private: PRUnichar *mUniStr; char *mCStr; }; - PRUint32 mLength; - PRUint32 mCurrentIdx; + PRUint32 mLength; + PRUint32 mCurrentIdx; PRUint32 mCurrentLength; nsTextFrame::TextStyle &mOldStyle;//base new styles on this one??? const SelectionDetails *mDetails; @@ -1004,8 +1004,8 @@ DrawSelectionIterator::DrawSelectionIterator(nsIContent *aContent, if (aContent) { nsRefPtr sc; sc = aPresContext->StyleSet()-> - ProbePseudoStyleFor(aContent->GetParent(), - nsCSSPseudoElements::mozSelection, aStyleContext); + ProbePseudoStyleFor(aContent->GetParent(), + nsCSSPseudoElements::mozSelection, aStyleContext); if (sc) { mSelectionPseudoStyle = PR_TRUE; const nsStyleBackground* bg = sc->GetStyleBackground(); @@ -1062,12 +1062,12 @@ DrawSelectionIterator::DrawSelectionIterator(nsIContent *aContent, } details= details->mNext; } - if (!mInit && mTypes) //we have details but none that we care about. - { - delete mTypes; - mTypes = nsnull; - mDone = PR_TRUE;//we are finished - } + if (!mInit && mTypes) //we have details but none that we care about. + { + delete mTypes; + mTypes = nsnull; + mDone = PR_TRUE;//we are finished + } } else if (details->mStart == details->mEnd)//no collapsed selections here! { @@ -1203,7 +1203,7 @@ DrawSelectionIterator::CurrentForeGroundColor() else if (mTypes[mCurrentIdx] | nsISelectionController::SELECTION_NORMAL)//Find color based on mTypes[mCurrentIdx]; { foreColor = mOldStyle.mSelectionTextColor; - colorSet = PR_TRUE; + colorSet = PR_TRUE; } if (colorSet && (foreColor != NS_DONT_CHANGE_COLOR)) { @@ -1305,12 +1305,9 @@ nsTextFrame::nsTextFrame() { // read in our global word selection prefs if ( !sWordSelectPrefInited ) { - nsCOMPtr prefBranch ( do_GetService(NS_PREFSERVICE_CONTRACTID) ); - if ( prefBranch ) { - PRBool temp = PR_FALSE; - prefBranch->GetBoolPref("layout.word_select.eat_space_to_next_word", &temp); - sWordSelectEatSpaceAfter = temp; - } + sWordSelectEatSpaceAfter = + nsContentUtils::GetBoolPref("layout.word_select.eat_space_to_next_word"); + sWordSelectPrefInited = PR_TRUE; } } @@ -1565,7 +1562,7 @@ nsTextFrame::PrepareUnicodeText(nsTextTransformer& aTX, // XXX This is a one to many mapping that I think isn't handled well if (nsnull != indexp) { *indexp++ = strInx; - strInx += wordLen; + strInx += wordLen; } } else if ('\n' == bp[0]) { @@ -1681,7 +1678,7 @@ nsTextFrame::PrepareUnicodeText(nsTextTransformer& aTX, } -//#define SHOW_SELECTION_CURSOR // should be turned off when the caret code is activated +//#define SHOW_SELECTION_CURSOR // should be turned off when the caret code is activated #ifdef SHOW_SELECTION_CURSOR @@ -1905,7 +1902,7 @@ nsTextFrame::PaintTextDecorations(nsIRenderingContext& aRenderingContext, aRenderingContext.SetColor(NS_RGB(255,255,128)); aRenderingContext.DrawRect(aX + startOffset, aY, textWidth, rect.height); #endif - aTextStyle.mNormalFont->GetUnderline(offset, size); + aTextStyle.mNormalFont->GetUnderline(offset, size); aRenderingContext.SetColor(IME_CONVERTED_COLOR); aRenderingContext.FillRect(aX + startOffset+size, aY + baseline - offset, textWidth-2*size, size); }break; @@ -1952,7 +1949,7 @@ nsTextFrame::GetContentAndOffsetsForSelection(nsIPresContext *aPresContext, nsIC nsIFrame *grandParent = parent->GetParent(); if (grandParent) { - nsIFrame *firstParent = grandParent->GetFirstChild(nsnull); + nsIFrame *firstParent = grandParent->GetFirstChild(nsnull); if (firstParent) { *aLength = 0; @@ -2392,7 +2389,7 @@ nsTextFrame::PaintUnicodeText(nsIPresContext* aPresContext, #ifdef IBMBIDI if (!isRightToLeftOnBidiPlatform) #endif - currentX+=newWidth;//increment twips X start + currentX += newWidth; // increment twips X start iter.Next(); } @@ -2517,23 +2514,22 @@ 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) ); - PRInt32 prefInt = 0; + PRInt32 prefInt = + nsContentUtils::GetIntPref("browser.drag_out_of_frame_style"); + PRBool outofstylehandled = PR_FALSE; - if (prefBranch) - { - if (NS_SUCCEEDED(prefBranch->GetIntPref("browser.drag_out_of_frame_style", &prefInt)) && prefInt) + + if (prefInt) + { + if (aPoint.y < origin.y)//above rectangle { - if (aPoint.y < origin.y)//above rectangle - { - aOffset = mContentOffset; - outofstylehandled = PR_TRUE; - } - else if ((aPoint.y - origin.y) > mRect.height) - { - aOffset = mContentOffset + mContentLength; - outofstylehandled = PR_TRUE; - } + aOffset = mContentOffset; + outofstylehandled = PR_TRUE; + } + else if ((aPoint.y - origin.y) > mRect.height) + { + aOffset = mContentOffset + mContentLength; + outofstylehandled = PR_TRUE; } } @@ -2995,19 +2991,19 @@ nsTextFrame::PaintTextSlowly(nsIPresContext* aPresContext, DrawSelectionIterator iter(content, details,text,(PRUint32)textLength,aTextStyle, selectionValue, aPresContext, mStyleContext); if (!iter.IsDone() && iter.First()) { - nscoord currentX = dx; - nsTextDimensions newDimensions;//temp - while (!iter.IsDone()) - { - PRUnichar *currenttext = iter.CurrentTextUnicharPtr(); - PRUint32 currentlength= iter.CurrentLength(); - //TextStyle ¤tStyle = iter.CurrentStyle(); - nscolor currentFGColor = iter.CurrentForeGroundColor(); - nscolor currentBKColor; - PRBool isCurrentBKColorTransparent; - GetTextDimensions(aRenderingContext,aTextStyle,currenttext, (PRInt32)currentlength,&newDimensions); - if (newDimensions.width) - { + nscoord currentX = dx; + nsTextDimensions newDimensions;//temp + while (!iter.IsDone()) + { + PRUnichar *currenttext = iter.CurrentTextUnicharPtr(); + PRUint32 currentlength= iter.CurrentLength(); + //TextStyle ¤tStyle = iter.CurrentStyle(); + nscolor currentFGColor = iter.CurrentForeGroundColor(); + nscolor currentBKColor; + PRBool isCurrentBKColorTransparent; + GetTextDimensions(aRenderingContext,aTextStyle,currenttext, (PRInt32)currentlength,&newDimensions); + if (newDimensions.width) + { if (iter.CurrentBackGroundColor(currentBKColor, &isCurrentBKColorTransparent)) {//DRAW RECT HERE!!! if (!isCurrentBKColorTransparent) { @@ -3016,25 +3012,26 @@ nsTextFrame::PaintTextSlowly(nsIPresContext* aPresContext, } currentFGColor = EnsureDifferentColors(currentFGColor, currentBKColor); } - } + } - if (isPaginated && !iter.IsBeforeOrAfter()) { - aRenderingContext.SetColor(nsCSSRendering::TransformColor(aTextStyle.mColor->mColor,canDarkenColor)); - RenderString(aRenderingContext, aStyleContext, aPresContext, - aTextStyle, currenttext, currentlength, - currentX, dy, width, details); - } else if (!isPaginated) { - aRenderingContext.SetColor(nsCSSRendering::TransformColor(currentFGColor,canDarkenColor)); - RenderString(aRenderingContext,aStyleContext, aPresContext, - aTextStyle, currenttext, currentlength, currentX, - dy, width, details); + if (isPaginated && !iter.IsBeforeOrAfter()) { + aRenderingContext.SetColor(nsCSSRendering::TransformColor(aTextStyle.mColor->mColor, canDarkenColor)); + RenderString(aRenderingContext, aStyleContext, aPresContext, + aTextStyle, currenttext, currentlength, + currentX, dy, width, details); + } else if (!isPaginated) { + aRenderingContext.SetColor(nsCSSRendering::TransformColor(currentFGColor, canDarkenColor)); + RenderString(aRenderingContext,aStyleContext, aPresContext, + aTextStyle, currenttext, currentlength, currentX, + dy, width, details); + } + + // increment twips X start but remember to get ready for + // next draw by reducing current x by letter spacing amount + currentX += newDimensions.width; // + aTextStyle.mLetterSpacing; + + iter.Next(); } - - //increment twips X start but remember to get ready for next draw by reducing current x by letter spacing amount - currentX+=newDimensions.width;// + aTextStyle.mLetterSpacing; - - iter.Next(); - } } else if (!isPaginated) { @@ -3393,25 +3390,23 @@ 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) ); - PRInt32 prefInt = 0; + PRInt32 prefInt = + nsContentUtils::GetIntPref("browser.drag_out_of_frame_style"); PRBool outofstylehandled = PR_FALSE; - if (prefBranch) - { - if (NS_SUCCEEDED(prefBranch->GetIntPref("browser.drag_out_of_frame_style", &prefInt)) && prefInt) + + if (prefInt) + { + if ((aPoint.y - origin.y) < 0)//above rectangle { - if ((aPoint.y - origin.y) < 0)//above rectangle - { - aContentOffset = mContentOffset; - aContentOffsetEnd = aContentOffset; - outofstylehandled = PR_TRUE; - } - else if ((aPoint.y - origin.y) > mRect.height) - { - aContentOffset = mContentOffset + mContentLength; - aContentOffsetEnd = aContentOffset; - outofstylehandled = PR_TRUE; - } + aContentOffset = mContentOffset; + aContentOffsetEnd = aContentOffset; + outofstylehandled = PR_TRUE; + } + else if ((aPoint.y - origin.y) > mRect.height) + { + aContentOffset = mContentOffset + mContentLength; + aContentOffsetEnd = aContentOffset; + outofstylehandled = PR_TRUE; } } @@ -3613,7 +3608,7 @@ nsTextFrame::SetSelected(nsIPresContext* aPresContext, if (shell) { nsCOMPtr selCon; nsresult rv = GetSelectionController(aPresContext, - getter_AddRefs(selCon)); + getter_AddRefs(selCon)); if (NS_SUCCEEDED(rv) && selCon) { frameSelection = do_QueryInterface(selCon); //this MAY implement diff --git a/mozilla/layout/html/base/src/nsTextTransformer.cpp b/mozilla/layout/html/base/src/nsTextTransformer.cpp index b3b442a2ab0..98565e03393 100644 --- a/mozilla/layout/html/base/src/nsTextTransformer.cpp +++ b/mozilla/layout/html/base/src/nsTextTransformer.cpp @@ -37,6 +37,7 @@ #include #include "nsCOMPtr.h" #include "nsTextTransformer.h" +#include "nsContentUtils.h" #include "nsIContent.h" #include "nsIFrame.h" #include "nsITextContent.h" @@ -48,29 +49,22 @@ #include "nsUnicharUtils.h" #include "nsICaseConversion.h" #include "prenv.h" -#include "nsIPrefBranchInternal.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" #ifdef IBMBIDI #include "nsLayoutAtoms.h" #endif -nsTextTransformer::WordSelectListener *nsTextTransformer::sWordSelectListener = nsnull; +PRBool nsTextTransformer::sWordSelectListenerPrefChecked = PR_FALSE; PRBool nsTextTransformer::sWordSelectStopAtPunctuation = PR_FALSE; static const char kWordSelectPref[] = "layout.word_select.stop_at_punctuation"; -NS_IMPL_ISUPPORTS1(nsTextTransformer::WordSelectListener, nsIObserver) - -NS_IMETHODIMP -nsTextTransformer::WordSelectListener::Observe(nsISupports *aSubject, - const char *aTopic, - const PRUnichar *aData) +// static +int +nsTextTransformer::WordSelectPrefCallback(const char* aPref, void* aClosure) { - NS_ASSERTION(!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID), - "wrong topic"); - nsCOMPtr prefBranch = do_QueryInterface(aSubject); - return prefBranch->GetBoolPref(kWordSelectPref, &sWordSelectStopAtPunctuation); + sWordSelectStopAtPunctuation = nsContentUtils::GetBoolPref(kWordSelectPref); + + return 0; } nsAutoTextBuffer::nsAutoTextBuffer() @@ -125,17 +119,14 @@ nsresult nsTextTransformer::Initialize() { // read in our global word selection prefs - if ( !sWordSelectListener ) { - nsCOMPtr prefBranch = - do_GetService( NS_PREFSERVICE_CONTRACTID ); - if ( prefBranch ) { - prefBranch->GetBoolPref(kWordSelectPref, &sWordSelectStopAtPunctuation); - sWordSelectListener = new WordSelectListener(); - if (sWordSelectListener) { - NS_ADDREF(sWordSelectListener); - prefBranch->AddObserver(kWordSelectPref, sWordSelectListener, PR_FALSE); - } - } + if ( !sWordSelectListenerPrefChecked ) { + sWordSelectListenerPrefChecked = PR_TRUE; + + sWordSelectStopAtPunctuation = + nsContentUtils::GetBoolPref(kWordSelectPref); + + nsContentUtils::RegisterPrefCallback(kWordSelectPref, + WordSelectPrefCallback, nsnull); } return NS_OK; @@ -155,7 +146,6 @@ static nsresult EnsureCaseConv() void nsTextTransformer::Shutdown() { - NS_IF_RELEASE(sWordSelectListener); if (gCaseConv) { nsServiceManager::ReleaseService(kUnicharUtilCID, gCaseConv); gCaseConv = nsnull; diff --git a/mozilla/layout/html/base/src/nsTextTransformer.h b/mozilla/layout/html/base/src/nsTextTransformer.h index 9b90dddb277..591499ab225 100644 --- a/mozilla/layout/html/base/src/nsTextTransformer.h +++ b/mozilla/layout/html/base/src/nsTextTransformer.h @@ -349,14 +349,9 @@ protected: PRUint8 mFlags; // prefs used to configure the double-click word selection behavior - class WordSelectListener: public nsIObserver { - public: - NS_DECL_ISUPPORTS - NS_DECL_NSIOBSERVER - }; - friend class WordSelectListener; - static WordSelectListener *sWordSelectListener; // have we read the prefs yet? - static PRBool sWordSelectStopAtPunctuation; // should we stop at punctuation? + static int WordSelectPrefCallback(const char* aPref, void* aClosure); + static PRBool sWordSelectListenerPrefChecked; // have we read the prefs yet? + static PRBool sWordSelectStopAtPunctuation; // should we stop at punctuation? #ifdef DEBUG static void SelfTest(nsILineBreaker* aLineBreaker, diff --git a/mozilla/layout/html/document/src/nsFrameSetFrame.cpp b/mozilla/layout/html/document/src/nsFrameSetFrame.cpp index 475dc5138a0..ab2c3e810cb 100644 --- a/mozilla/layout/html/document/src/nsFrameSetFrame.cpp +++ b/mozilla/layout/html/document/src/nsFrameSetFrame.cpp @@ -37,6 +37,7 @@ * ***** END LICENSE BLOCK ***** */ #include "nsCOMPtr.h" #include "nsFrameSetFrame.h" +#include "nsContentUtils.h" #include "nsIHTMLContent.h" #include "nsLeafFrame.h" #include "nsHTMLContainerFrame.h" @@ -63,9 +64,6 @@ #include "nsIComponentManager.h" #include "nsGUIEvent.h" #include "nsIRenderingContext.h" -#include "nsIPrefService.h" -#include "nsIPrefBranch.h" -#include "nsIPrefBranchInternal.h" #include "nsIServiceManager.h" #include "nsIDOMMutationEvent.h" #include "nsINameSpaceManager.h" @@ -82,7 +80,7 @@ #define ALL_VIS 0x000F #define NONE_VIS 0x0000 -static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); +static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); /******************************************************************************* * nsFramesetDrag @@ -241,32 +239,17 @@ nsHTMLFramesetFrame::nsHTMLFramesetFrame() mChildFrameborder = nsnull; mChildBorderColors = nsnull; mForceFrameResizability = PR_FALSE; - mPrefBranchWeakRef = nsnull; } nsHTMLFramesetFrame::~nsHTMLFramesetFrame() { - delete [] mRowSizes; - delete [] mColSizes; + delete[] mRowSizes; + delete[] mColSizes; delete[] mVerBorders; delete[] mHorBorders; - mRowSizes = mColSizes = nsnull; - - nsCOMPtr prefBranch = - do_QueryReferent(mPrefBranchWeakRef); - - if (prefBranch) { -#ifdef DEBUG - nsresult rv = -#endif - prefBranch->RemoveObserver(kFrameResizePref, this); - - NS_ASSERTION(NS_SUCCEEDED(rv), - "Can't remove frameset as pref branch observer"); - } - - mPrefBranchWeakRef = nsnull; + nsContentUtils::UnregisterPrefCallback(kFrameResizePref, + FrameResizePrefCallback, this); } nsresult nsHTMLFramesetFrame::QueryInterface(const nsIID& aIID, @@ -274,10 +257,9 @@ nsresult nsHTMLFramesetFrame::QueryInterface(const nsIID& aIID, { if (NULL == aInstancePtr) { return NS_ERROR_NULL_POINTER; - } else if (aIID.Equals(NS_GET_IID(nsHTMLFramesetFrame))) { - *aInstancePtr = (void*)this; - return NS_OK; - } else if (aIID.Equals(NS_GET_IID(nsIObserver))) { + } + + if (aIID.Equals(NS_GET_IID(nsHTMLFramesetFrame))) { *aInstancePtr = (void*)this; return NS_OK; } @@ -285,42 +267,34 @@ nsresult nsHTMLFramesetFrame::QueryInterface(const nsIID& aIID, return nsHTMLContainerFrame::QueryInterface(aIID, aInstancePtr); } -nsrefcnt nsHTMLFramesetFrame::AddRef(void) +// static +int +nsHTMLFramesetFrame::FrameResizePrefCallback(const char* aPref, void* aClosure) { - return 0; -} + nsHTMLFramesetFrame *frame = + NS_REINTERPRET_CAST(nsHTMLFramesetFrame *, aClosure); -nsrefcnt nsHTMLFramesetFrame::Release(void) -{ - return 0; -} - -NS_IMETHODIMP -nsHTMLFramesetFrame::Observe(nsISupports* aObject, const char* aAction, - const PRUnichar* aPrefName) -{ - nsAutoString prefName(aPrefName); - if (prefName.Equals(NS_LITERAL_STRING(kFrameResizePref))) { - nsIDocument* doc = mContent->GetDocument(); - mozAutoDocUpdate updateBatch(doc, UPDATE_CONTENT_MODEL, PR_TRUE); - if (doc) { - doc->AttributeWillChange(mContent, - kNameSpaceID_None, - nsHTMLAtoms::frameborder); - } - nsCOMPtr prefBranch(do_QueryInterface(aObject)); - if (prefBranch) { - prefBranch->GetBoolPref(kFrameResizePref, &mForceFrameResizability); - } - RecalculateBorderResize(); - if (doc) { - doc->AttributeChanged(mContent, - kNameSpaceID_None, - nsHTMLAtoms::frameborder, - nsIDOMMutationEvent::MODIFICATION); - } + nsIDocument* doc = frame->mContent->GetDocument(); + mozAutoDocUpdate updateBatch(doc, UPDATE_CONTENT_MODEL, PR_TRUE); + if (doc) { + doc->AttributeWillChange(frame->mContent, + kNameSpaceID_None, + nsHTMLAtoms::frameborder); } - return NS_OK; + + frame->mForceFrameResizability = + nsContentUtils::GetBoolPref(kFrameResizePref, + frame->mForceFrameResizability); + + frame->RecalculateBorderResize(); + if (doc) { + doc->AttributeChanged(frame->mContent, + kNameSpaceID_None, + nsHTMLAtoms::frameborder, + nsIDOMMutationEvent::MODIFICATION); + } + + return 0; } static NS_DEFINE_IID(kViewCID, NS_VIEW_CID); @@ -997,12 +971,10 @@ nsHTMLFramesetFrame::Reflow(nsIPresContext* aPresContext, PRBool firstTime = (eReflowReason_Initial == aReflowState.reason); if (firstTime) { - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - mPrefBranchWeakRef = do_GetWeakReference(prefBranch); - prefBranch->AddObserver(kFrameResizePref, this, PR_FALSE); - prefBranch->GetBoolPref(kFrameResizePref, &mForceFrameResizability); - } + nsContentUtils::RegisterPrefCallback(kFrameResizePref, + FrameResizePrefCallback, this); + mForceFrameResizability = + nsContentUtils::GetBoolPref(kFrameResizePref); } // subtract out the width of all of the potential borders. There are diff --git a/mozilla/layout/html/document/src/nsFrameSetFrame.h b/mozilla/layout/html/document/src/nsFrameSetFrame.h index e424b8fa27b..f59c059f2ac 100644 --- a/mozilla/layout/html/document/src/nsFrameSetFrame.h +++ b/mozilla/layout/html/document/src/nsFrameSetFrame.h @@ -103,8 +103,7 @@ struct nsFramesetDrag { /******************************************************************************* * nsHTMLFramesetFrame ******************************************************************************/ -class nsHTMLFramesetFrame : public nsHTMLContainerFrame, - public nsIObserver +class nsHTMLFramesetFrame : public nsHTMLContainerFrame { public: // Woohoo, concrete class with an IID! @@ -114,8 +113,7 @@ public: virtual ~nsHTMLFramesetFrame(); - NS_DECL_ISUPPORTS - NS_DECL_NSIOBSERVER + NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); NS_IMETHOD Init(nsIPresContext* aPresContext, nsIContent* aContent, @@ -243,6 +241,8 @@ protected: PRBool ChildIsFrameset(nsIFrame* aChild); + static int FrameResizePrefCallback(const char* aPref, void* aClosure); + PRInt32 mNumRows; nscoord* mRowSizes; // currently computed row sizes PRInt32 mNumCols; @@ -271,7 +271,6 @@ protected: nsBorderColor* mChildBorderColors; PRBool mForceFrameResizability; - nsWeakPtr mPrefBranchWeakRef; }; diff --git a/mozilla/layout/html/style/src/Makefile.in b/mozilla/layout/html/style/src/Makefile.in index cde054d38df..2266a174e03 100644 --- a/mozilla/layout/html/style/src/Makefile.in +++ b/mozilla/layout/html/style/src/Makefile.in @@ -59,6 +59,8 @@ REQUIRES = xpcom \ plugin \ xuldoc \ imglib2 \ + js \ + xpconnect \ $(NULL) CPPSRCS = \ diff --git a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp index 57b8fd39242..c090826d615 100644 --- a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp @@ -91,8 +91,6 @@ #include "nsISupportsArray.h" #include "nsIAnonymousContentCreator.h" #include "nsFrameManager.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" #include "nsLegendFrame.h" #include "nsIContentIterator.h" #include "nsBoxLayoutState.h" @@ -101,6 +99,7 @@ #include "nsIElementFactory.h" #include "nsITheme.h" #include "nsContentCID.h" +#include "nsContentUtils.h" #include "nsIDocShell.h" #include "nsFormControlHelper.h" #include "nsObjectFrame.h" @@ -1265,12 +1264,8 @@ nsCSSFrameConstructor::nsCSSFrameConstructor(nsIDocument *aDocument) if (!gGotXBLFormPrefs) { gGotXBLFormPrefs = PR_TRUE; - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - prefBranch->GetBoolPref("nglayout.debug.enable_xbl_forms", - &gUseXBLForms); - - } + gUseXBLForms = + nsContentUtils::GetBoolPref("nglayout.debug.enable_xbl_forms"); } #ifdef DEBUG @@ -12513,7 +12508,7 @@ nsCSSFrameConstructor::ConstructBlock(nsIPresShell* aPresShell, // ...and that we're the absolute containing block. nsFrameConstructorSaveState absoluteSaveState; if (aRelPos || !aState.mAbsoluteItems.containingBlock) { - NS_ASSERTION(aRelPos, "should have made area frame for this"); + // NS_ASSERTION(aRelPos, "should have made area frame for this"); aState.PushAbsoluteContainingBlock(aPresContext, aNewFrame, absoluteSaveState); } diff --git a/mozilla/layout/printing/nsPrintEngine.cpp b/mozilla/layout/printing/nsPrintEngine.cpp index 4316ba8dd97..551e4b1983f 100644 --- a/mozilla/layout/printing/nsPrintEngine.cpp +++ b/mozilla/layout/printing/nsPrintEngine.cpp @@ -142,8 +142,6 @@ static const char kPrintingPromptService[] = "@mozilla.org/embedcomp/printingpro #include "nsIViewManager.h" #include "nsIView.h" -#include "nsIPrefService.h" -#include "nsIPrefBranch.h" #include "nsIPageSequenceFrame.h" #include "nsIURL.h" #include "nsIContentViewerEdit.h" @@ -738,13 +736,8 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings, mPrt->mPrintSettings->GetPrintSilent(&printSilently); // Check prefs for a default setting as to whether we should print silently - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - PRBool alwaysPrintSilent; - if (NS_SUCCEEDED(prefBranch->GetBoolPref("print.always_print_silent", &alwaysPrintSilent))) { - printSilently = alwaysPrintSilent; - } - } + printSilently = nsContentUtils::GetBoolPref("print.always_print_silent", + printSilently); // Ask dialog to be Print Shown via the Plugable Printing Dialog Service // This service is for the Print Dialog and the Print Progress Dialog @@ -1586,10 +1579,7 @@ nsPrintEngine::CheckDocumentForPPCaching() // Only check if it is the first time into PP if (!mOldPrtPreview) { // First check the Pref - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - prefBranch->GetBoolPref("print.always_cache_old_pres", &cacheOldPres); - } + cacheOldPres = nsContentUtils::GetBoolPref("print.always_cache_old_pres"); // Temp fix for FrameSet Print Preview Bugs if (!cacheOldPres && mPrt->mPrintObject->mFrameType == eFrameSet) { @@ -1660,10 +1650,8 @@ nsPrintEngine::ShowPrintProgress(PRBool aIsForPrinting, PRBool& aDoNotify) // if it is already being shown then don't bother to find out if it should be // so skip this and leave mShowProgressDialog set to FALSE if (!mPrt->mProgressDialogIsShown) { - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - prefBranch->GetBoolPref("print.show_print_progress", &mPrt->mShowProgressDialog); - } + mPrt->mShowProgressDialog = + nsContentUtils::GetBoolPref("print.show_print_progress"); } // Turning off the showing of Print Progress in Prefs overrides @@ -2218,9 +2206,8 @@ nsresult nsPrintEngine::CleanupOnFailure(nsresult aResult, PRBool aIsPrinting) void nsPrintEngine::ShowPrintErrorDialog(nsresult aPrintError, PRBool aIsPrinting) { - nsresult rv; - - PR_PL(("nsPrintEngine::ShowPrintErrorDialog(nsresult aPrintError=%lx, PRBool aIsPrinting=%d)\n", (long)rv, (int)aIsPrinting)); + + PR_PL(("nsPrintEngine::ShowPrintErrorDialog(nsresult aPrintError=%lx, PRBool aIsPrinting=%d)\n", (long)aPrintError, (int)aIsPrinting)); static NS_DEFINE_CID(kCStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); nsCOMPtr stringBundleService = do_GetService(kCStringBundleServiceCID); @@ -2230,7 +2217,7 @@ nsPrintEngine::ShowPrintErrorDialog(nsresult aPrintError, PRBool aIsPrinting) return; } nsCOMPtr myStringBundle; - rv = stringBundleService->CreateBundle(NS_ERROR_GFX_PRINTER_BUNDLE_URL, getter_AddRefs(myStringBundle)); + nsresult rv = stringBundleService->CreateBundle(NS_ERROR_GFX_PRINTER_BUNDLE_URL, getter_AddRefs(myStringBundle)); if (NS_FAILED(rv)) { PR_PL(("ShowPrintErrorDialog(): CreateBundle() failure for NS_ERROR_GFX_PRINTER_BUNDLE_URL, rv=%lx\n", (long)rv)); return; @@ -5017,14 +5004,10 @@ PRBool nsPrintEngine::mIsDoingRuntimeTesting = PR_FALSE; void nsPrintEngine::InitializeTestRuntimeError() { - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - mIsDoingRuntimeTesting = PR_FALSE; - prefBranch->GetBoolPref("print.doing_runtime_error_checking", &mIsDoingRuntimeTesting); - } + mIsDoingRuntimeTesting = + nsContentUtils::GetBoolPref("print.doing_runtime_error_checking"); mLayoutDebugObj = do_GetService("@mozilla.org/debug/debugobject;1"); - } PRBool diff --git a/mozilla/layout/svg/renderer/src/libart/nsSVGLibartPathGeometry.cpp b/mozilla/layout/svg/renderer/src/libart/nsSVGLibartPathGeometry.cpp index 065c30fcdf1..2e711a05ad3 100644 --- a/mozilla/layout/svg/renderer/src/libart/nsSVGLibartPathGeometry.cpp +++ b/mozilla/layout/svg/renderer/src/libart/nsSVGLibartPathGeometry.cpp @@ -49,7 +49,6 @@ #include "nsSVGFill.h" #include "nsSVGStroke.h" #include "nsIServiceManager.h" -#include "nsIPref.h" #include "nsMemory.h" #include "prdtoa.h" diff --git a/mozilla/layout/svg/renderer/src/libart/nsSVGStroke.cpp b/mozilla/layout/svg/renderer/src/libart/nsSVGStroke.cpp index 4c8e9b4e1fa..1806ea9c919 100644 --- a/mozilla/layout/svg/renderer/src/libart/nsSVGStroke.cpp +++ b/mozilla/layout/svg/renderer/src/libart/nsSVGStroke.cpp @@ -39,7 +39,6 @@ #include "nsSVGStroke.h" #include "nsCOMPtr.h" #include "nsIServiceManager.h" -#include "nsIPref.h" #include "nsMemory.h" #include "nsISVGPathGeometrySource.h" #include "prdtoa.h" diff --git a/mozilla/layout/xul/base/src/nsBoxFrame.cpp b/mozilla/layout/xul/base/src/nsBoxFrame.cpp index 8457fc9eb24..ed6b428794d 100644 --- a/mozilla/layout/xul/base/src/nsBoxFrame.cpp +++ b/mozilla/layout/xul/base/src/nsBoxFrame.cpp @@ -80,8 +80,6 @@ #include "nsIPresShell.h" #include "nsFrameNavigator.h" #include "nsCSSRendering.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" #include "nsIServiceManager.h" #include "nsBoxToBlockAdaptor.h" #include "nsIBoxLayout.h" @@ -104,6 +102,7 @@ #include "nsIEventListenerManager.h" #include "nsIEventStateManager.h" #include "nsIDOMEvent.h" +#include "nsContentUtils.h" // Needed for Print Preview #include "nsIDocument.h" @@ -1401,11 +1400,7 @@ nsBoxFrame::CheckFrameOrder() void nsBoxFrame::GetDebugPref(nsIPresContext* aPresContext) { - gDebug = PR_FALSE; - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - prefBranch->GetBoolPref("xul.debug.box", &gDebug); - } + gDebug = nsContentUtils::GetBoolPref("xul.debug.box"); } NS_IMETHODIMP diff --git a/mozilla/layout/xul/base/src/nsMenuBarListener.cpp b/mozilla/layout/xul/base/src/nsMenuBarListener.cpp index 3a60dd037c3..0aca56b5a5c 100644 --- a/mozilla/layout/xul/base/src/nsMenuBarListener.cpp +++ b/mozilla/layout/xul/base/src/nsMenuBarListener.cpp @@ -64,9 +64,7 @@ #include "nsIViewManager.h" #include "nsIView.h" #include "nsISupportsArray.h" - -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" +#include "nsContentUtils.h" /* * nsMenuBarListener implementation @@ -117,17 +115,9 @@ void nsMenuBarListener::InitAccessKey() #endif // Get the menu access key value from prefs, overriding the default: - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) - { - nsresult rv = prefBranch->GetIntPref("ui.key.menuAccessKey", &mAccessKey); - rv |= prefBranch->GetBoolPref("ui.key.menuAccessKeyFocuses", - &mAccessKeyFocuses); -#ifdef DEBUG_akkana - NS_ASSERTION(NS_SUCCEEDED(rv) && prefBranch, - "Menubar listener couldn't get accel key from prefs!\n"); -#endif - } + mAccessKey = nsContentUtils::GetIntPref("ui.key.menuAccessKey", mAccessKey); + mAccessKeyFocuses = + nsContentUtils::GetBoolPref("ui.key.menuAccessKeyFocuses"); } //////////////////////////////////////////////////////////////////////// diff --git a/mozilla/layout/xul/base/src/nsMenuFrame.cpp b/mozilla/layout/xul/base/src/nsMenuFrame.cpp index f344d43b627..99405258349 100644 --- a/mozilla/layout/xul/base/src/nsMenuFrame.cpp +++ b/mozilla/layout/xul/base/src/nsMenuFrame.cpp @@ -75,8 +75,6 @@ #include "nsIXBLService.h" #include "nsCSSFrameConstructor.h" #include "nsIDOMKeyEvent.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" #include "nsIScrollableView.h" #include "nsXPIDLString.h" #include "nsReadableUtils.h" @@ -85,6 +83,8 @@ #include "nsGUIEvent.h" #include "nsIEventStateManager.h" #include "nsITimerInternal.h" +#include "nsContentUtils.h" + #define NS_MENU_POPUP_LIST_INDEX 0 #if defined(XP_WIN) || defined(XP_OS2) @@ -1524,9 +1524,7 @@ nsMenuFrame::BuildAcceleratorText() #endif // Get the accelerator key value from prefs, overriding the default: - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) - prefBranch->GetIntPref("ui.key.accelKey", &accelKey); + accelKey = nsContentUtils::GetIntPref("ui.key.accelKey", accelKey); } nsAutoString modifiers; diff --git a/mozilla/layout/xul/base/src/nsSliderFrame.cpp b/mozilla/layout/xul/base/src/nsSliderFrame.cpp index 300176bf450..58eb4ed7e9a 100644 --- a/mozilla/layout/xul/base/src/nsSliderFrame.cpp +++ b/mozilla/layout/xul/base/src/nsSliderFrame.cpp @@ -73,10 +73,9 @@ #include "nsRepeatService.h" #include "nsBoxLayoutState.h" #include "nsSprocketLayout.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" #include "nsIServiceManager.h" #include "nsGUIEvent.h" +#include "nsContentUtils.h" PRBool nsSliderFrame::gMiddlePref = PR_FALSE; PRInt32 nsSliderFrame::gSnapMultiplier = 6; @@ -123,21 +122,20 @@ nsSliderFrame::~nsSliderFrame() NS_IMETHODIMP nsSliderFrame::Init(nsIPresContext* aPresContext, - nsIContent* aContent, - nsIFrame* aParent, - nsStyleContext* aContext, - nsIFrame* aPrevInFlow) + nsIContent* aContent, + nsIFrame* aParent, + nsStyleContext* aContext, + nsIFrame* aPrevInFlow) { - nsresult rv = nsBoxFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow); + nsresult rv = nsBoxFrame::Init(aPresContext, aContent, aParent, aContext, + aPrevInFlow); static PRBool gotPrefs = PR_FALSE; if (!gotPrefs) { gotPrefs = PR_TRUE; - nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); - if (prefBranch) { - prefBranch->GetBoolPref("middlemouse.scrollbarPosition", &gMiddlePref); - prefBranch->GetIntPref("slider.snapMultiplier", &gSnapMultiplier); - } + + gMiddlePref = nsContentUtils::GetBoolPref("middlemouse.scrollbarPosition"); + gSnapMultiplier = nsContentUtils::GetIntPref("slider.snapMultiplier"); } CreateViewForFrame(aPresContext,this,aContext,PR_TRUE); diff --git a/mozilla/layout/xul/base/src/nsTextBoxFrame.cpp b/mozilla/layout/xul/base/src/nsTextBoxFrame.cpp index 35cecaa2217..3db36c21ec7 100644 --- a/mozilla/layout/xul/base/src/nsTextBoxFrame.cpp +++ b/mozilla/layout/xul/base/src/nsTextBoxFrame.cpp @@ -58,9 +58,6 @@ #include "nsINameSpaceManager.h" #include "nsBoxLayoutState.h" #include "nsMenuBarListener.h" -#include "nsIPrefBranch.h" -#include "nsIPrefService.h" -#include "nsIPrefLocalizedString.h" #include "nsXPIDLString.h" #include "nsIServiceManager.h" #include "nsIDocument.h" @@ -69,6 +66,7 @@ #include "nsIEventStateManager.h" #include "nsITheme.h" #include "nsUnicharUtils.h" +#include "nsContentUtils.h" #ifdef IBMBIDI #include "nsBidiUtils.h" @@ -199,23 +197,8 @@ nsTextBoxFrame::AlwaysAppendAccessKey() { gAccessKeyPrefInitialized = PR_TRUE; - nsCOMPtr prefBranch = - do_GetService(NS_PREFSERVICE_CONTRACTID); - - if (prefBranch) - { - nsCOMPtr prefValue; - prefBranch->GetComplexValue("intl.menuitems.alwaysappendaccesskeys", - NS_GET_IID(nsIPrefLocalizedString), - getter_AddRefs(prefValue)); - if (prefValue) - { - nsXPIDLString prefString; - prefValue->ToString(getter_Copies(prefString)); - gAlwaysAppendAccessKey = - nsDependentString(prefString).Equals(NS_LITERAL_STRING("true")); - } - } + gAlwaysAppendAccessKey = + nsContentUtils::GetCharPref("intl.menuitems.alwaysappendaccesskeys").Equals("true"); } return gAlwaysAppendAccessKey; } diff --git a/mozilla/layout/xul/base/src/nsXULTooltipListener.cpp b/mozilla/layout/xul/base/src/nsXULTooltipListener.cpp index 8aa0c97a041..76fe664d09b 100644 --- a/mozilla/layout/xul/base/src/nsXULTooltipListener.cpp +++ b/mozilla/layout/xul/base/src/nsXULTooltipListener.cpp @@ -47,9 +47,6 @@ #include "nsIPresShell.h" #include "nsIFrame.h" #include "nsIPopupBoxObject.h" -#include "nsIPrefBranch.h" -#include "nsIPrefBranchInternal.h" -#include "nsIPrefService.h" #include "nsIServiceManager.h" #ifdef MOZ_XUL #include "nsITreeView.h" @@ -60,6 +57,7 @@ #include "nsIScriptContext.h" #include "nsIScriptGlobalObject.h" #include "nsIDOMWindowInternal.h" +#include "nsContentUtils.h" ////////////////////////////////////////////////////////////////////////// //// nsISupports @@ -82,11 +80,9 @@ nsXULTooltipListener::~nsXULTooltipListener() { HideTooltip(); - nsCOMPtr prefInternal(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefInternal) { - // Unregister our pref observer - prefInternal->RemoveObserver("browser.chrome.toolbar_tips", this); - } + // Unregister our pref observer + nsContentUtils::UnregisterPrefCallback("browser.chrome.toolbar_tips", + ToolbarTipsPrefChanged, this); } NS_IMPL_ADDREF(nsXULTooltipListener) @@ -97,7 +93,6 @@ NS_INTERFACE_MAP_BEGIN(nsXULTooltipListener) NS_INTERFACE_MAP_ENTRY(nsIDOMMouseMotionListener) NS_INTERFACE_MAP_ENTRY(nsIDOMKeyListener) NS_INTERFACE_MAP_ENTRY(nsIDOMXULListener) - NS_INTERFACE_MAP_ENTRY(nsIObserver) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMEventListener, nsIDOMMouseListener) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMMouseMotionListener) NS_INTERFACE_MAP_END @@ -242,29 +237,20 @@ nsXULTooltipListener::HandleEvent(nsIDOMEvent* aEvent) return NS_OK; } -////////////////////////////////////////////////////////////////////////// -//// nsIObserver - -NS_IMETHODIMP -nsXULTooltipListener::Observe(nsISupports* aSubject, - const char* aTopic, - const PRUnichar* aData) -{ - if (nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) { - NS_ERROR("unknown nsIObserver topic!"); - return NS_ERROR_UNEXPECTED; - } - - nsCOMPtr prefBranch(do_QueryInterface(aSubject)); - NS_ASSERTION(prefBranch, "Pref change topic with no pref subject?"); - prefBranch->GetBoolPref("browser.chrome.toolbar_tips", &sShowTooltips); - - return NS_OK; -} - ////////////////////////////////////////////////////////////////////////// //// nsXULTooltipListener +// static +int +nsXULTooltipListener::ToolbarTipsPrefChanged(const char *aPref, + void *aClosure) +{ + sShowTooltips = nsContentUtils::GetBoolPref("browser.chrome.toolbar_tips", + sShowTooltips); + + return 0; +} + NS_IMETHODIMP nsXULTooltipListener::PopupHiding(nsIDOMEvent* aEvent) { @@ -277,6 +263,7 @@ nsXULTooltipListener::PopupHiding(nsIDOMEvent* aEvent) PRBool nsXULTooltipListener::sShowTooltips = PR_FALSE; +// XXX: This could all be done in the ctor. nsresult nsXULTooltipListener::Init(nsIContent* aSourceNode, nsIRootBox* aRootBox) { @@ -290,22 +277,13 @@ nsXULTooltipListener::Init(nsIContent* aSourceNode, nsIRootBox* aRootBox) mIsSourceTree = mSourceNode->Tag() == nsXULAtoms::treechildren; #endif - static PRBool prefChangeRegistered = PR_FALSE; + // get the initial value of the pref + sShowTooltips = + nsContentUtils::GetBoolPref("browser.chrome.toolbar_tips", sShowTooltips); - // Only the first time, register the callback and get the initial value of the pref - if (!prefChangeRegistered) { - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefBranch) { - // get the initial value of the pref - nsresult rv = prefBranch->GetBoolPref("browser.chrome.toolbar_tips", &sShowTooltips); - if (NS_SUCCEEDED(rv)) { - // register the callback so we get notified of updates - rv = prefBranch->AddObserver("browser.chrome.toolbar_tips", this, PR_FALSE); - if (NS_SUCCEEDED(rv)) - prefChangeRegistered = PR_TRUE; - } - } - } + // register the callback so we get notified of updates + nsContentUtils::RegisterPrefCallback("browser.chrome.toolbar_tips", + ToolbarTipsPrefChanged, this); return NS_OK; } diff --git a/mozilla/layout/xul/base/src/nsXULTooltipListener.h b/mozilla/layout/xul/base/src/nsXULTooltipListener.h index 3162e91ebcf..32894b1d9eb 100644 --- a/mozilla/layout/xul/base/src/nsXULTooltipListener.h +++ b/mozilla/layout/xul/base/src/nsXULTooltipListener.h @@ -43,7 +43,6 @@ #include "nsIDOMKeyListener.h" #include "nsIDOMMouseEvent.h" #include "nsIDOMXULListener.h" -#include "nsIObserver.h" #include "nsIContent.h" #include "nsIDOMElement.h" #include "nsITimer.h" @@ -58,8 +57,7 @@ class nsXULTooltipListener : public nsIDOMMouseListener, public nsIDOMMouseMotionListener, public nsIDOMKeyListener, - public nsIDOMXULListener, - public nsIObserver + public nsIDOMXULListener { public: @@ -99,8 +97,6 @@ public: // nsIDOMEventListener NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent); - NS_DECL_NSIOBSERVER - nsresult Init(nsIContent* aSourceNode, nsIRootBox* aRootBox); nsresult SetDefaultTooltip(nsIContent* aDefaultTooltip); nsresult GetDefaultTooltip(nsIContent** aDefaultTooltip); @@ -127,6 +123,8 @@ protected: nsresult DestroyTooltip(); nsresult GetTooltipFor(nsIContent* aTarget, nsIContent** aTooltip); + static int ToolbarTipsPrefChanged(const char *aPref, void *aClosure); + nsIRootBox* mRootBox; nsIContent* mSourceNode; nsCOMPtr mTargetNode;