diff --git a/mozilla/content/base/src/nsDocumentViewer.cpp b/mozilla/content/base/src/nsDocumentViewer.cpp index db748e18215..4f308a7fd64 100644 --- a/mozilla/content/base/src/nsDocumentViewer.cpp +++ b/mozilla/content/base/src/nsDocumentViewer.cpp @@ -812,7 +812,11 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget, if (NS_FAILED(rv)) return rv; - mPresContext->Init(aDeviceContext); + rv = mPresContext->Init(aDeviceContext); + if (NS_FAILED(rv)) { + mPresContext = nsnull; + return rv; + } #if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW) makeCX = !GetIsPrintPreview(); // needs to be true except when we are already in PP @@ -1393,7 +1397,11 @@ DocumentViewerImpl::Show(void) mPresContext = do_CreateInstance(kGalleyContextCID, &rv); NS_ENSURE_SUCCESS(rv, rv); - mPresContext->Init(mDeviceContext); + rv = mPresContext->Init(mDeviceContext); + if (NS_FAILED(rv)) { + mPresContext = nsnull; + return rv; + } nsRect tbounds; mParentWidget->GetBounds(tbounds); diff --git a/mozilla/content/base/src/nsPrintEngine.cpp b/mozilla/content/base/src/nsPrintEngine.cpp index 81b09f6c70f..d02ac9d3c17 100644 --- a/mozilla/content/base/src/nsPrintEngine.cpp +++ b/mozilla/content/base/src/nsPrintEngine.cpp @@ -2603,7 +2603,11 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink) // init it with the DC - (aPO->mPresContext)->Init(mPrt->mPrintDocDC); + rv = aPO->mPresContext->Init(mPrt->mPrintDocDC); + if (NS_FAILED(rv)) { + aPO->mPresContext = nsnull; + return rv; + } rv = mDocViewerPrint->CreateStyleSet(aPO->mDocument, &aPO->mStyleSet); NS_ENSURE_SUCCESS(rv, rv); diff --git a/mozilla/content/base/src/nsRuleNode.cpp b/mozilla/content/base/src/nsRuleNode.cpp index bcdd22b9440..1239a8eddfa 100644 --- a/mozilla/content/base/src/nsRuleNode.cpp +++ b/mozilla/content/base/src/nsRuleNode.cpp @@ -330,13 +330,10 @@ static PRBool SetColor(const nsCSSValue& aValue, const nscolor aParentColor, else if (eCSSUnit_Integer == unit) { PRInt32 intValue = aValue.GetIntValue(); if (0 <= intValue) { - nsILookAndFeel* look = nsnull; - if (NS_SUCCEEDED(aPresContext->GetLookAndFeel(&look)) && look) { - nsILookAndFeel::nsColorID colorID = (nsILookAndFeel::nsColorID) intValue; - if (NS_SUCCEEDED(look->GetColor(colorID, aResult))) { - result = PR_TRUE; - } - NS_RELEASE(look); + nsILookAndFeel* look = aPresContext->LookAndFeel(); + nsILookAndFeel::nsColorID colorID = (nsILookAndFeel::nsColorID) intValue; + if (NS_SUCCEEDED(look->GetColor(colorID, aResult))) { + result = PR_TRUE; } } else { diff --git a/mozilla/content/events/src/nsEventStateManager.cpp b/mozilla/content/events/src/nsEventStateManager.cpp index 2d5e1480dd3..c49f5023482 100644 --- a/mozilla/content/events/src/nsEventStateManager.cpp +++ b/mozilla/content/events/src/nsEventStateManager.cpp @@ -1366,8 +1366,7 @@ nsEventStateManager::GenerateDragGesture(nsIPresContext* aPresContext, static PRInt32 pixelThresholdY = 0; if (!pixelThresholdX) { - nsCOMPtr lf; - aPresContext->GetLookAndFeel(getter_AddRefs(lf)); + nsILookAndFeel *lf = aPresContext->LookAndFeel(); lf->GetMetric(nsILookAndFeel::eMetric_DragThresholdX, pixelThresholdX); lf->GetMetric(nsILookAndFeel::eMetric_DragThresholdY, pixelThresholdY); if (!pixelThresholdX) diff --git a/mozilla/editor/libeditor/html/nsHTMLObjectResizer.cpp b/mozilla/editor/libeditor/html/nsHTMLObjectResizer.cpp index a5514e3c725..04a0733b6f0 100644 --- a/mozilla/editor/libeditor/html/nsHTMLObjectResizer.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLObjectResizer.cpp @@ -66,9 +66,12 @@ #include "nsIPresContext.h" #include "nsILookAndFeel.h" +#include "nsWidgetsCID.h" class nsHTMLEditUtils; +static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); + // ================================================================== // DocumentResizeEventListener // ================================================================== @@ -911,19 +914,12 @@ nsHTMLEditor::MouseMove(nsIDOMEvent* aMouseEvent) mouseEvent->GetClientX(&clientX); mouseEvent->GetClientY(&clientY); - nsCOMPtr ps = do_QueryReferent(mPresShellWeak); - if (!ps) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr pcontext; - ps->GetPresContext(getter_AddRefs(pcontext)); - if (!pcontext) return NS_ERROR_NOT_INITIALIZED; - nsCOMPtr look; - nsresult res = pcontext->GetLookAndFeel(getter_AddRefs(look)); + nsCOMPtr look = do_GetService(kLookAndFeelCID); + NS_ASSERTION(look, "Look and feel service must be implemented for this toolkit"); PRInt32 xThreshold=1, yThreshold=1; - if (NS_SUCCEEDED(res) && look) { - look->GetMetric(nsILookAndFeel::eMetric_DragThresholdX, xThreshold); - look->GetMetric(nsILookAndFeel::eMetric_DragThresholdY, yThreshold); - } + look->GetMetric(nsILookAndFeel::eMetric_DragThresholdX, xThreshold); + look->GetMetric(nsILookAndFeel::eMetric_DragThresholdY, yThreshold); if (PR_ABS(clientX - mOriginalX ) * 2 >= xThreshold || PR_ABS(clientY - mOriginalY ) * 2 >= yThreshold) { diff --git a/mozilla/gfx/src/shared/nsNativeTheme.cpp b/mozilla/gfx/src/shared/nsNativeTheme.cpp index 123b913ecc4..cf7cf371f8f 100644 --- a/mozilla/gfx/src/shared/nsNativeTheme.cpp +++ b/mozilla/gfx/src/shared/nsNativeTheme.cpp @@ -219,10 +219,7 @@ nsNativeTheme::IsWidgetStyled(nsIPresContext* aPresContext, nsIFrame* aFrame, float p2t; aPresContext->GetPixelsToTwips(&p2t); - nsCOMPtr lookAndFeel; - aPresContext->GetLookAndFeel(getter_AddRefs(lookAndFeel)); - if (!lookAndFeel) - return PR_TRUE; + nsILookAndFeel *lookAndFeel = aPresContext->LookAndFeel(); switch (aWidgetType) { case NS_THEME_BUTTON: diff --git a/mozilla/gfx/src/windows/nsNativeThemeWin.cpp b/mozilla/gfx/src/windows/nsNativeThemeWin.cpp index 8ea3de24d54..201a19a4af1 100644 --- a/mozilla/gfx/src/windows/nsNativeThemeWin.cpp +++ b/mozilla/gfx/src/windows/nsNativeThemeWin.cpp @@ -1067,10 +1067,7 @@ PRBool nsNativeThemeWin::IsWidgetStyled(nsIPresContext* aPresContext, nsIFrame* float p2t; aPresContext->GetPixelsToTwips(&p2t); - nsCOMPtr lookAndFeel; - aPresContext->GetLookAndFeel(getter_AddRefs(lookAndFeel)); - if (!lookAndFeel) - return PR_TRUE; + nsILookAndFeel *lookAndFeel = aPresContext->LookAndFeel(); switch (aWidgetType) { case NS_THEME_BUTTON: { diff --git a/mozilla/layout/base/nsCaret.cpp b/mozilla/layout/base/nsCaret.cpp index efc5b4b3add..52e9481579a 100644 --- a/mozilla/layout/base/nsCaret.cpp +++ b/mozilla/layout/base/nsCaret.cpp @@ -60,7 +60,6 @@ #include "nsIViewManager.h" #include "nsIPresContext.h" #include "nsILookAndFeel.h" -#include "nsWidgetsCID.h" // for NS_LOOKANDFEEL_CID #include "nsBlockFrame.h" #include "nsISelectionController.h" @@ -115,12 +114,12 @@ NS_IMETHODIMP nsCaret::Init(nsIPresShell *inPresShell) NS_ASSERTION(mPresShell, "Hey, pres shell should support weak refs"); // get nsILookAndFeel from the pres context, which has one cached. - nsCOMPtr lookAndFeel; + nsILookAndFeel *lookAndFeel = nsnull; nsCOMPtr presContext; inPresShell->GetPresContext(getter_AddRefs(presContext)); if (presContext) - presContext->GetLookAndFeel(getter_AddRefs(lookAndFeel)); + lookAndFeel = presContext->LookAndFeel(); if (lookAndFeel) { PRInt32 tempInt; diff --git a/mozilla/layout/base/nsDocumentViewer.cpp b/mozilla/layout/base/nsDocumentViewer.cpp index db748e18215..4f308a7fd64 100644 --- a/mozilla/layout/base/nsDocumentViewer.cpp +++ b/mozilla/layout/base/nsDocumentViewer.cpp @@ -812,7 +812,11 @@ DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget, if (NS_FAILED(rv)) return rv; - mPresContext->Init(aDeviceContext); + rv = mPresContext->Init(aDeviceContext); + if (NS_FAILED(rv)) { + mPresContext = nsnull; + return rv; + } #if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW) makeCX = !GetIsPrintPreview(); // needs to be true except when we are already in PP @@ -1393,7 +1397,11 @@ DocumentViewerImpl::Show(void) mPresContext = do_CreateInstance(kGalleyContextCID, &rv); NS_ENSURE_SUCCESS(rv, rv); - mPresContext->Init(mDeviceContext); + rv = mPresContext->Init(mDeviceContext); + if (NS_FAILED(rv)) { + mPresContext = nsnull; + return rv; + } nsRect tbounds; mParentWidget->GetBounds(tbounds); diff --git a/mozilla/layout/base/nsPresContext.cpp b/mozilla/layout/base/nsPresContext.cpp index 72cf6032005..3fe87211ff4 100644 --- a/mozilla/layout/base/nsPresContext.cpp +++ b/mozilla/layout/base/nsPresContext.cpp @@ -61,7 +61,6 @@ #include "nsContentPolicyUtils.h" #include "nsIScriptGlobalObject.h" #include "nsIDOMWindow.h" -#include "nsNetUtil.h" #include "nsXPIDLString.h" #include "nsIWeakReferenceUtils.h" #include "nsCSSRendering.h" @@ -171,12 +170,6 @@ nsPresContext::nsPresContext() mDefaultColor = NS_RGB(0x00, 0x00, 0x00); mDefaultBackgroundColor = NS_RGB(0xFF, 0xFF, 0xFF); - nsILookAndFeel* look = nsnull; - if (NS_SUCCEEDED(GetLookAndFeel(&look)) && look) { - look->GetColor(nsILookAndFeel::eColor_WindowForeground, mDefaultColor); - look->GetColor(nsILookAndFeel::eColor_WindowBackground, mDefaultBackgroundColor); - NS_RELEASE(look); - } mUseDocumentColors = PR_TRUE; mUseDocumentFonts = PR_TRUE; @@ -238,6 +231,7 @@ nsPresContext::~nsPresContext() #endif // IBMBIDI NS_IF_RELEASE(mDeviceContext); + NS_IF_RELEASE(mLookAndFeel); } NS_IMPL_ISUPPORTS2(nsPresContext, nsIPresContext, nsIObserver) @@ -435,15 +429,12 @@ nsPresContext::GetDocumentColorPreferences() } } else { - // Without this here, checking the "use system colors" checkbox - // has no affect until the constructor is called again mDefaultColor = NS_RGB(0x00, 0x00, 0x00); mDefaultBackgroundColor = NS_RGB(0xFF, 0xFF, 0xFF); - nsCOMPtr look; - if (NS_SUCCEEDED(GetLookAndFeel(getter_AddRefs(look))) && look) { - look->GetColor(nsILookAndFeel::eColor_WindowForeground, mDefaultColor); - look->GetColor(nsILookAndFeel::eColor_WindowBackground, mDefaultBackgroundColor); - } + mLookAndFeel->GetColor(nsILookAndFeel::eColor_WindowForeground, + mDefaultColor); + mLookAndFeel->GetColor(nsILookAndFeel::eColor_WindowBackground, + mDefaultBackgroundColor); } if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.use_document_colors", &boolPref))) { @@ -632,6 +623,14 @@ nsPresContext::Init(nsIDeviceContext* aDeviceContext) mDeviceContext = aDeviceContext; NS_IF_ADDREF(mDeviceContext); + // Get the look and feel service here; default colors will be initialized + // from calling GetUserPreferences() below. + nsresult rv = CallGetService(kLookAndFeelCID, &mLookAndFeel); + if (NS_FAILED(rv)) { + NS_ERROR("LookAndFeel service must be implemented for this toolkit"); + return rv; + } + mLangService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID); mPrefs = do_GetService(NS_PREF_CONTRACTID); if (mPrefs) { @@ -840,43 +839,6 @@ nsPresContext::SetImageAnimationMode(PRUint16 aMode) mImageAnimationMode = aMode; } -/* - * It is no longer necesary to hold on to presContext just to get a - * nsILookAndFeel, which can now be obtained through the service - * manager. However, this cached copy can be used when a pres context - * is available, for faster performance. - */ -NS_IMETHODIMP -nsPresContext::GetLookAndFeel(nsILookAndFeel** aLookAndFeel) -{ - NS_PRECONDITION(aLookAndFeel, "null out param"); - if (! mLookAndFeel) { - nsresult rv; - mLookAndFeel = do_GetService(kLookAndFeelCID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - } - *aLookAndFeel = mLookAndFeel; - NS_ADDREF(*aLookAndFeel); - return NS_OK; -} - -/* - * Get the cached IO service, faster than the service manager could. - */ -NS_IMETHODIMP -nsPresContext::GetIOService(nsIIOService** aIOService) -{ - NS_PRECONDITION(aIOService, "null out param"); - if (! mIOService) { - nsresult rv; - mIOService = do_GetIOService(&rv); - NS_ENSURE_SUCCESS(rv, rv); - } - *aIOService = mIOService; - NS_ADDREF(*aIOService); - return NS_OK; -} - NS_IMETHODIMP nsPresContext::GetBaseURL(nsIURI** aResult) { @@ -1296,25 +1258,6 @@ nsPresContext::GetDeviceContext(nsIDeviceContext** aResult) const return NS_OK; } -NS_IMETHODIMP -nsPresContext::GetImageLoadFlags(nsLoadFlags& aLoadFlags) -{ - aLoadFlags = nsIRequest::LOAD_NORMAL; - - nsCOMPtr doc; - (void) mShell->GetDocument(getter_AddRefs(doc)); - - if (doc) { - nsCOMPtr loadGroup = doc->GetDocumentLoadGroup(); - - if (loadGroup) { - loadGroup->GetLoadFlags(&aLoadFlags); - } - } - - return NS_OK; -} - NS_IMETHODIMP nsPresContext::LoadImage(nsIURI* aURL, nsIFrame* aTargetFrame,//may be null (precached image) diff --git a/mozilla/layout/base/nsPresContext.h b/mozilla/layout/base/nsPresContext.h index e24b2cea5f7..511df07a5d5 100644 --- a/mozilla/layout/base/nsPresContext.h +++ b/mozilla/layout/base/nsPresContext.h @@ -70,7 +70,6 @@ class nsString; class nsIEventStateManager; class nsIURI; class nsILookAndFeel; -class nsIIOService; class nsICSSPseudoComparator; class nsILanguageAtom; class nsITheme; @@ -161,19 +160,10 @@ public: virtual void SetImageAnimationMode(PRUint16 aMode) = 0; /** - * Get an special load flags for images for this context + * Get cached look and feel service. This is faster than obtaining it + * through the service manager. */ - NS_IMETHOD GetImageLoadFlags(nsLoadFlags& aLoadFlags) = 0; - - /** - * Get cached look and feel service. - */ - NS_IMETHOD GetLookAndFeel(nsILookAndFeel** aLookAndFeel) = 0; - - /** - * Get cached IO service. - */ - NS_IMETHOD GetIOService(nsIIOService** aIOService) = 0; + nsILookAndFeel* LookAndFeel() { return mLookAndFeel; } /** * Get base url for presentation @@ -577,6 +567,7 @@ protected: // since there is no dependency // from gfx back to layout. nsIEventStateManager* mEventManager; // [STRONG] + nsILookAndFeel* mLookAndFeel; // [STRONG] nsCompatibility mCompatibilityMode; PRUint16 mImageAnimationMode; diff --git a/mozilla/layout/base/nsPresShell.cpp b/mozilla/layout/base/nsPresShell.cpp index 66ab0dfe425..6300e14f66c 100644 --- a/mozilla/layout/base/nsPresShell.cpp +++ b/mozilla/layout/base/nsPresShell.cpp @@ -7064,7 +7064,8 @@ PresShell::VerifyIncrementalReflow() NS_ASSERTION(NS_SUCCEEDED (rv), "failed to create presentation context"); nsCOMPtr dc; mPresContext->GetDeviceContext(getter_AddRefs(dc)); - cx->Init(dc); + rv = cx->Init(dc); + NS_ENSURE_SUCCESS(rv, rv); // Get our scrolling preference nsScrollPreference scrolling; diff --git a/mozilla/layout/base/public/nsIPresContext.h b/mozilla/layout/base/public/nsIPresContext.h index e24b2cea5f7..511df07a5d5 100644 --- a/mozilla/layout/base/public/nsIPresContext.h +++ b/mozilla/layout/base/public/nsIPresContext.h @@ -70,7 +70,6 @@ class nsString; class nsIEventStateManager; class nsIURI; class nsILookAndFeel; -class nsIIOService; class nsICSSPseudoComparator; class nsILanguageAtom; class nsITheme; @@ -161,19 +160,10 @@ public: virtual void SetImageAnimationMode(PRUint16 aMode) = 0; /** - * Get an special load flags for images for this context + * Get cached look and feel service. This is faster than obtaining it + * through the service manager. */ - NS_IMETHOD GetImageLoadFlags(nsLoadFlags& aLoadFlags) = 0; - - /** - * Get cached look and feel service. - */ - NS_IMETHOD GetLookAndFeel(nsILookAndFeel** aLookAndFeel) = 0; - - /** - * Get cached IO service. - */ - NS_IMETHOD GetIOService(nsIIOService** aIOService) = 0; + nsILookAndFeel* LookAndFeel() { return mLookAndFeel; } /** * Get base url for presentation @@ -577,6 +567,7 @@ protected: // since there is no dependency // from gfx back to layout. nsIEventStateManager* mEventManager; // [STRONG] + nsILookAndFeel* mLookAndFeel; // [STRONG] nsCompatibility mCompatibilityMode; PRUint16 mImageAnimationMode; diff --git a/mozilla/layout/base/public/nsPresContext.h b/mozilla/layout/base/public/nsPresContext.h index e24b2cea5f7..511df07a5d5 100644 --- a/mozilla/layout/base/public/nsPresContext.h +++ b/mozilla/layout/base/public/nsPresContext.h @@ -70,7 +70,6 @@ class nsString; class nsIEventStateManager; class nsIURI; class nsILookAndFeel; -class nsIIOService; class nsICSSPseudoComparator; class nsILanguageAtom; class nsITheme; @@ -161,19 +160,10 @@ public: virtual void SetImageAnimationMode(PRUint16 aMode) = 0; /** - * Get an special load flags for images for this context + * Get cached look and feel service. This is faster than obtaining it + * through the service manager. */ - NS_IMETHOD GetImageLoadFlags(nsLoadFlags& aLoadFlags) = 0; - - /** - * Get cached look and feel service. - */ - NS_IMETHOD GetLookAndFeel(nsILookAndFeel** aLookAndFeel) = 0; - - /** - * Get cached IO service. - */ - NS_IMETHOD GetIOService(nsIIOService** aIOService) = 0; + nsILookAndFeel* LookAndFeel() { return mLookAndFeel; } /** * Get base url for presentation @@ -577,6 +567,7 @@ protected: // since there is no dependency // from gfx back to layout. nsIEventStateManager* mEventManager; // [STRONG] + nsILookAndFeel* mLookAndFeel; // [STRONG] nsCompatibility mCompatibilityMode; PRUint16 mImageAnimationMode; diff --git a/mozilla/layout/base/src/nsCaret.cpp b/mozilla/layout/base/src/nsCaret.cpp index efc5b4b3add..52e9481579a 100644 --- a/mozilla/layout/base/src/nsCaret.cpp +++ b/mozilla/layout/base/src/nsCaret.cpp @@ -60,7 +60,6 @@ #include "nsIViewManager.h" #include "nsIPresContext.h" #include "nsILookAndFeel.h" -#include "nsWidgetsCID.h" // for NS_LOOKANDFEEL_CID #include "nsBlockFrame.h" #include "nsISelectionController.h" @@ -115,12 +114,12 @@ NS_IMETHODIMP nsCaret::Init(nsIPresShell *inPresShell) NS_ASSERTION(mPresShell, "Hey, pres shell should support weak refs"); // get nsILookAndFeel from the pres context, which has one cached. - nsCOMPtr lookAndFeel; + nsILookAndFeel *lookAndFeel = nsnull; nsCOMPtr presContext; inPresShell->GetPresContext(getter_AddRefs(presContext)); if (presContext) - presContext->GetLookAndFeel(getter_AddRefs(lookAndFeel)); + lookAndFeel = presContext->LookAndFeel(); if (lookAndFeel) { PRInt32 tempInt; diff --git a/mozilla/layout/base/src/nsPresContext.cpp b/mozilla/layout/base/src/nsPresContext.cpp index 72cf6032005..3fe87211ff4 100644 --- a/mozilla/layout/base/src/nsPresContext.cpp +++ b/mozilla/layout/base/src/nsPresContext.cpp @@ -61,7 +61,6 @@ #include "nsContentPolicyUtils.h" #include "nsIScriptGlobalObject.h" #include "nsIDOMWindow.h" -#include "nsNetUtil.h" #include "nsXPIDLString.h" #include "nsIWeakReferenceUtils.h" #include "nsCSSRendering.h" @@ -171,12 +170,6 @@ nsPresContext::nsPresContext() mDefaultColor = NS_RGB(0x00, 0x00, 0x00); mDefaultBackgroundColor = NS_RGB(0xFF, 0xFF, 0xFF); - nsILookAndFeel* look = nsnull; - if (NS_SUCCEEDED(GetLookAndFeel(&look)) && look) { - look->GetColor(nsILookAndFeel::eColor_WindowForeground, mDefaultColor); - look->GetColor(nsILookAndFeel::eColor_WindowBackground, mDefaultBackgroundColor); - NS_RELEASE(look); - } mUseDocumentColors = PR_TRUE; mUseDocumentFonts = PR_TRUE; @@ -238,6 +231,7 @@ nsPresContext::~nsPresContext() #endif // IBMBIDI NS_IF_RELEASE(mDeviceContext); + NS_IF_RELEASE(mLookAndFeel); } NS_IMPL_ISUPPORTS2(nsPresContext, nsIPresContext, nsIObserver) @@ -435,15 +429,12 @@ nsPresContext::GetDocumentColorPreferences() } } else { - // Without this here, checking the "use system colors" checkbox - // has no affect until the constructor is called again mDefaultColor = NS_RGB(0x00, 0x00, 0x00); mDefaultBackgroundColor = NS_RGB(0xFF, 0xFF, 0xFF); - nsCOMPtr look; - if (NS_SUCCEEDED(GetLookAndFeel(getter_AddRefs(look))) && look) { - look->GetColor(nsILookAndFeel::eColor_WindowForeground, mDefaultColor); - look->GetColor(nsILookAndFeel::eColor_WindowBackground, mDefaultBackgroundColor); - } + mLookAndFeel->GetColor(nsILookAndFeel::eColor_WindowForeground, + mDefaultColor); + mLookAndFeel->GetColor(nsILookAndFeel::eColor_WindowBackground, + mDefaultBackgroundColor); } if (NS_SUCCEEDED(mPrefs->GetBoolPref("browser.display.use_document_colors", &boolPref))) { @@ -632,6 +623,14 @@ nsPresContext::Init(nsIDeviceContext* aDeviceContext) mDeviceContext = aDeviceContext; NS_IF_ADDREF(mDeviceContext); + // Get the look and feel service here; default colors will be initialized + // from calling GetUserPreferences() below. + nsresult rv = CallGetService(kLookAndFeelCID, &mLookAndFeel); + if (NS_FAILED(rv)) { + NS_ERROR("LookAndFeel service must be implemented for this toolkit"); + return rv; + } + mLangService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID); mPrefs = do_GetService(NS_PREF_CONTRACTID); if (mPrefs) { @@ -840,43 +839,6 @@ nsPresContext::SetImageAnimationMode(PRUint16 aMode) mImageAnimationMode = aMode; } -/* - * It is no longer necesary to hold on to presContext just to get a - * nsILookAndFeel, which can now be obtained through the service - * manager. However, this cached copy can be used when a pres context - * is available, for faster performance. - */ -NS_IMETHODIMP -nsPresContext::GetLookAndFeel(nsILookAndFeel** aLookAndFeel) -{ - NS_PRECONDITION(aLookAndFeel, "null out param"); - if (! mLookAndFeel) { - nsresult rv; - mLookAndFeel = do_GetService(kLookAndFeelCID, &rv); - NS_ENSURE_SUCCESS(rv, rv); - } - *aLookAndFeel = mLookAndFeel; - NS_ADDREF(*aLookAndFeel); - return NS_OK; -} - -/* - * Get the cached IO service, faster than the service manager could. - */ -NS_IMETHODIMP -nsPresContext::GetIOService(nsIIOService** aIOService) -{ - NS_PRECONDITION(aIOService, "null out param"); - if (! mIOService) { - nsresult rv; - mIOService = do_GetIOService(&rv); - NS_ENSURE_SUCCESS(rv, rv); - } - *aIOService = mIOService; - NS_ADDREF(*aIOService); - return NS_OK; -} - NS_IMETHODIMP nsPresContext::GetBaseURL(nsIURI** aResult) { @@ -1296,25 +1258,6 @@ nsPresContext::GetDeviceContext(nsIDeviceContext** aResult) const return NS_OK; } -NS_IMETHODIMP -nsPresContext::GetImageLoadFlags(nsLoadFlags& aLoadFlags) -{ - aLoadFlags = nsIRequest::LOAD_NORMAL; - - nsCOMPtr doc; - (void) mShell->GetDocument(getter_AddRefs(doc)); - - if (doc) { - nsCOMPtr loadGroup = doc->GetDocumentLoadGroup(); - - if (loadGroup) { - loadGroup->GetLoadFlags(&aLoadFlags); - } - } - - return NS_OK; -} - NS_IMETHODIMP nsPresContext::LoadImage(nsIURI* aURL, nsIFrame* aTargetFrame,//may be null (precached image) diff --git a/mozilla/layout/base/src/nsPresContext.h b/mozilla/layout/base/src/nsPresContext.h index 0ff88bcce2f..51cd98c1bc4 100644 --- a/mozilla/layout/base/src/nsPresContext.h +++ b/mozilla/layout/base/src/nsPresContext.h @@ -49,8 +49,6 @@ #include "nsIURL.h" #include "nsIEventStateManager.h" #include "nsIObserver.h" -#include "nsILookAndFeel.h" -#include "nsIIOService.h" #ifdef IBMBIDI #include "nsBidiUtils.h" #endif @@ -73,9 +71,6 @@ public: NS_IMETHOD SetShell(nsIPresShell* aShell); virtual void SetCompatibilityMode(nsCompatibility aMode); virtual void SetImageAnimationMode(PRUint16 aMode); - NS_IMETHOD GetImageLoadFlags(nsLoadFlags& aLoadFlags); - NS_IMETHOD GetLookAndFeel(nsILookAndFeel** aLookAndFeel); - NS_IMETHOD GetIOService(nsIIOService** aIOService); NS_IMETHOD GetBaseURL(nsIURI** aURLResult); NS_IMETHOD GetMedium(nsIAtom** aMediumResult) = 0; NS_IMETHOD ClearStyleDataAndReflow(void); @@ -217,8 +212,6 @@ protected: nsLanguageSpecificTransformType mLanguageSpecificTransformType; nsILinkHandler* mLinkHandler; // [WEAK] nsWeakPtr mContainer; - nsCOMPtr mLookAndFeel; - nsCOMPtr mIOService; nsFont mDefaultVariableFont; nsFont mDefaultFixedFont; diff --git a/mozilla/layout/base/src/nsPrintContext.cpp b/mozilla/layout/base/src/nsPrintContext.cpp index a609f75b677..23ebfb90a8e 100644 --- a/mozilla/layout/base/src/nsPrintContext.cpp +++ b/mozilla/layout/base/src/nsPrintContext.cpp @@ -59,7 +59,6 @@ public: PrintContext(); ~PrintContext(); - NS_IMETHOD GetImageLoadFlags(nsLoadFlags& aLoadFlags); NS_IMETHOD GetMedium(nsIAtom** aMedium); NS_IMETHOD IsPaginated(PRBool* aResult); NS_IMETHOD SetPaginatedScrolling(PRBool aResult) { return NS_ERROR_FAILURE; } @@ -108,13 +107,6 @@ PrintContext::QueryInterface(REFNSIID aIID, void** aInstancePtr) return nsPresContext::QueryInterface(aIID, aInstancePtr); } -NS_IMETHODIMP -PrintContext::GetImageLoadFlags(nsLoadFlags& aLoadFlags) -{ - aLoadFlags = nsIRequest::LOAD_FROM_CACHE | nsIRequest::VALIDATE_NEVER | nsIRequest::LOAD_NORMAL; - return NS_OK; -} - NS_IMETHODIMP PrintContext::GetMedium(nsIAtom** aResult) { diff --git a/mozilla/layout/base/src/nsPrintPreviewContext.cpp b/mozilla/layout/base/src/nsPrintPreviewContext.cpp index 18d719f14d5..22b938d718c 100644 --- a/mozilla/layout/base/src/nsPrintPreviewContext.cpp +++ b/mozilla/layout/base/src/nsPrintPreviewContext.cpp @@ -56,7 +56,6 @@ public: // another class. Only the base class should use NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS_INHERITED - NS_IMETHOD GetImageLoadFlags(nsLoadFlags& aLoadFlags); NS_IMETHOD GetMedium(nsIAtom** aMedium); NS_IMETHOD IsPaginated(PRBool* aResult); NS_IMETHOD SetPaginatedScrolling(PRBool aResult) { mCanPaginatedScroll = aResult; return NS_OK; } @@ -118,13 +117,6 @@ PrintPreviewContext::GetMedium(nsIAtom** aResult) return NS_OK; } -NS_IMETHODIMP -PrintPreviewContext::GetImageLoadFlags(nsLoadFlags& aLoadFlags) -{ - aLoadFlags = nsIRequest::LOAD_FROM_CACHE | nsIRequest::VALIDATE_NEVER | nsIRequest::LOAD_NORMAL; - return NS_OK; -} - NS_IMETHODIMP PrintPreviewContext::IsPaginated(PRBool* aResult) { diff --git a/mozilla/layout/build/nsLayoutModule.cpp b/mozilla/layout/build/nsLayoutModule.cpp index 194616a903d..eb316c1e05e 100644 --- a/mozilla/layout/build/nsLayoutModule.cpp +++ b/mozilla/layout/build/nsLayoutModule.cpp @@ -131,6 +131,7 @@ #include "nsLayoutCID.h" #include "nsImageLoadingContent.h" #include "nsStyleSet.h" +#include "nsImageFrame.h" // view stuff #include "nsViewsCID.h" @@ -348,6 +349,7 @@ Shutdown(nsIModule* aSelf) nsTextTransformer::Shutdown(); nsSpaceManager::Shutdown(); nsTextControlFrame::ReleaseGlobals(); + nsImageFrame::ReleaseGlobals(); NS_IF_RELEASE(nsContentDLF::gUAStyleSheet); NS_IF_RELEASE(nsRuleNode::gLangService); diff --git a/mozilla/layout/forms/nsFormControlFrame.cpp b/mozilla/layout/forms/nsFormControlFrame.cpp index 00c69c2e1ba..563c39dcd9a 100644 --- a/mozilla/layout/forms/nsFormControlFrame.cpp +++ b/mozilla/layout/forms/nsFormControlFrame.cpp @@ -871,10 +871,9 @@ nsFormControlFrame::GetScreenHeight(nsIPresContext* aPresContext, nscoord& aHeig nsRect screen; PRBool dropdownCanOverlapOSBar = PR_FALSE; - nsCOMPtr lookAndFeel; - aPresContext->GetLookAndFeel(getter_AddRefs(lookAndFeel)); - if ( lookAndFeel ) - lookAndFeel->GetMetric(nsILookAndFeel::eMetric_MenusCanOverlapOSBar, dropdownCanOverlapOSBar); + nsILookAndFeel *lookAndFeel = aPresContext->LookAndFeel(); + lookAndFeel->GetMetric(nsILookAndFeel::eMetric_MenusCanOverlapOSBar, + dropdownCanOverlapOSBar); if ( dropdownCanOverlapOSBar ) context->GetRect ( screen ); else diff --git a/mozilla/layout/forms/nsListControlFrame.cpp b/mozilla/layout/forms/nsListControlFrame.cpp index 1189a4b952c..742e158716b 100644 --- a/mozilla/layout/forms/nsListControlFrame.cpp +++ b/mozilla/layout/forms/nsListControlFrame.cpp @@ -84,7 +84,6 @@ #include "nsISelectElement.h" #include "nsIPrivateDOMEvent.h" #include "nsCSSRendering.h" -#include "nsILookAndFeel.h" #include "nsReflowPath.h" #include "nsITheme.h" #include "nsIDOMMouseListener.h" @@ -689,14 +688,10 @@ void nsListControlFrame::PaintFocus(nsIRenderingContext& aRC, nsFramePaintLayer // set up back stop colors and then ask L&F service for the real colors nscolor color; - nsCOMPtr lookAndFeel; - mPresContext->GetLookAndFeel(getter_AddRefs(lookAndFeel)); - if (lookAndFeel){ - lookAndFeel->GetColor(lastItemIsSelected?nsILookAndFeel::eColor_WidgetSelectForeground:nsILookAndFeel::eColor_WidgetSelectBackground, color); - } else { - // Use some backstop colors if for some reason we don't have a L&F object - color = lastItemIsSelected? NS_RGB(245,219,149) : NS_RGB(0,0,0); - } + mPresContext->LookAndFeel()-> + GetColor(lastItemIsSelected ? + nsILookAndFeel::eColor_WidgetSelectForeground : + nsILookAndFeel::eColor_WidgetSelectBackground, color); float p2t; mPresContext->GetScaledPixelsToTwips(&p2t); diff --git a/mozilla/layout/generic/nsImageFrame.cpp b/mozilla/layout/generic/nsImageFrame.cpp index a4c63f6293a..8f9f8f5d70e 100644 --- a/mozilla/layout/generic/nsImageFrame.cpp +++ b/mozilla/layout/generic/nsImageFrame.cpp @@ -123,6 +123,9 @@ // - created if null, deleted if refcount goes to 0 nsImageFrame::IconLoad* nsImageFrame::mIconLoad = nsnull; +// cached IO service for loading icons +nsIIOService* nsImageFrame::sIOService; + // test if the width and height are fixed, looking at the style data static PRBool HaveFixedSize(const nsStylePosition* aStylePosition) { @@ -1819,10 +1822,14 @@ nsImageFrame::LoadIcon(const nsAString& aSpec, nsresult rv = NS_OK; NS_PRECONDITION(!aSpec.IsEmpty(), "What happened??"); + if (!sIOService) { + static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); + rv = CallGetService(kIOServiceCID, &sIOService); + NS_ENSURE_SUCCESS(rv, rv); + } + nsCOMPtr realURI; - nsCOMPtr ioService; - aPresContext->GetIOService(getter_AddRefs(ioService)); - SpecToURI(aSpec, ioService, getter_AddRefs(realURI)); + SpecToURI(aSpec, sIOService, getter_AddRefs(realURI)); nsCOMPtr il(do_GetService("@mozilla.org/image/loader;1", &rv)); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/layout/generic/nsImageFrame.h b/mozilla/layout/generic/nsImageFrame.h index ff24a560efd..f7623590584 100644 --- a/mozilla/layout/generic/nsImageFrame.h +++ b/mozilla/layout/generic/nsImageFrame.h @@ -42,6 +42,7 @@ #include "nsAString.h" #include "nsIPresContext.h" #include "nsIImageFrame.h" +#include "nsIIOService.h" #include "nsTransform2D.h" #include "imgIRequest.h" @@ -137,6 +138,8 @@ public: NS_IMETHOD GetIntrinsicImageSize(nsSize& aSize); + static void ReleaseGlobals() { NS_IF_RELEASE(sIOService); } + protected: // nsISupports NS_IMETHOD_(nsrefcnt) AddRef(void); @@ -248,6 +251,8 @@ private: nsIPresContext* mPresContext; // weak ref + static nsIIOService* sIOService; + /* loading / broken image icon support */ // XXXbz this should be handled by the prescontext, I think; that diff --git a/mozilla/layout/generic/nsTextFrame.cpp b/mozilla/layout/generic/nsTextFrame.cpp index 5f846f50355..580ea011140 100644 --- a/mozilla/layout/generic/nsTextFrame.cpp +++ b/mozilla/layout/generic/nsTextFrame.cpp @@ -568,12 +568,11 @@ public: // Get colors from look&feel mSelectionBGColor = NS_RGB(0, 0, 0); mSelectionTextColor = NS_RGB(255, 255, 255); - nsILookAndFeel* look = nsnull; - if (NS_SUCCEEDED(aPresContext->GetLookAndFeel(&look)) && look) { - look->GetColor(nsILookAndFeel::eColor_TextSelectBackground, mSelectionBGColor); - look->GetColor(nsILookAndFeel::eColor_TextSelectForeground, mSelectionTextColor); - NS_RELEASE(look); - } + nsILookAndFeel* look = aPresContext->LookAndFeel(); + look->GetColor(nsILookAndFeel::eColor_TextSelectBackground, + mSelectionBGColor); + look->GetColor(nsILookAndFeel::eColor_TextSelectForeground, + mSelectionTextColor); // Get the word and letter spacing mWordSpacing = 0; @@ -1021,15 +1020,15 @@ DrawSelectionIterator::DrawSelectionIterator(nsIContent *aContent, } // Get background colors for disabled selection at attention-getting selection (used with type ahead find) - nsCOMPtr look; - if (NS_SUCCEEDED(aPresContext->GetLookAndFeel(getter_AddRefs(look))) && look) { - look->GetColor(nsILookAndFeel::eColor_TextSelectBackgroundAttention, mAttentionColor); - look->GetColor(nsILookAndFeel::eColor_TextSelectBackgroundDisabled, mDisabledColor); - mDisabledColor = EnsureDifferentColors(mDisabledColor, mOldStyle.mSelectionBGColor); - mAttentionColor = EnsureDifferentColors(mAttentionColor, mOldStyle.mSelectionBGColor); - } - else - mDisabledColor = mAttentionColor = mOldStyle.mSelectionBGColor; + nsILookAndFeel *look = aPresContext->LookAndFeel(); + look->GetColor(nsILookAndFeel::eColor_TextSelectBackgroundAttention, + mAttentionColor); + look->GetColor(nsILookAndFeel::eColor_TextSelectBackgroundDisabled, + mDisabledColor); + mDisabledColor = EnsureDifferentColors(mDisabledColor, + mOldStyle.mSelectionBGColor); + mAttentionColor = EnsureDifferentColors(mAttentionColor, + mOldStyle.mSelectionBGColor); if (!aSelDetails) { diff --git a/mozilla/layout/html/base/src/nsImageFrame.cpp b/mozilla/layout/html/base/src/nsImageFrame.cpp index a4c63f6293a..8f9f8f5d70e 100644 --- a/mozilla/layout/html/base/src/nsImageFrame.cpp +++ b/mozilla/layout/html/base/src/nsImageFrame.cpp @@ -123,6 +123,9 @@ // - created if null, deleted if refcount goes to 0 nsImageFrame::IconLoad* nsImageFrame::mIconLoad = nsnull; +// cached IO service for loading icons +nsIIOService* nsImageFrame::sIOService; + // test if the width and height are fixed, looking at the style data static PRBool HaveFixedSize(const nsStylePosition* aStylePosition) { @@ -1819,10 +1822,14 @@ nsImageFrame::LoadIcon(const nsAString& aSpec, nsresult rv = NS_OK; NS_PRECONDITION(!aSpec.IsEmpty(), "What happened??"); + if (!sIOService) { + static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); + rv = CallGetService(kIOServiceCID, &sIOService); + NS_ENSURE_SUCCESS(rv, rv); + } + nsCOMPtr realURI; - nsCOMPtr ioService; - aPresContext->GetIOService(getter_AddRefs(ioService)); - SpecToURI(aSpec, ioService, getter_AddRefs(realURI)); + SpecToURI(aSpec, sIOService, getter_AddRefs(realURI)); nsCOMPtr il(do_GetService("@mozilla.org/image/loader;1", &rv)); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/layout/html/base/src/nsImageFrame.h b/mozilla/layout/html/base/src/nsImageFrame.h index ff24a560efd..f7623590584 100644 --- a/mozilla/layout/html/base/src/nsImageFrame.h +++ b/mozilla/layout/html/base/src/nsImageFrame.h @@ -42,6 +42,7 @@ #include "nsAString.h" #include "nsIPresContext.h" #include "nsIImageFrame.h" +#include "nsIIOService.h" #include "nsTransform2D.h" #include "imgIRequest.h" @@ -137,6 +138,8 @@ public: NS_IMETHOD GetIntrinsicImageSize(nsSize& aSize); + static void ReleaseGlobals() { NS_IF_RELEASE(sIOService); } + protected: // nsISupports NS_IMETHOD_(nsrefcnt) AddRef(void); @@ -248,6 +251,8 @@ private: nsIPresContext* mPresContext; // weak ref + static nsIIOService* sIOService; + /* loading / broken image icon support */ // XXXbz this should be handled by the prescontext, I think; that diff --git a/mozilla/layout/html/base/src/nsPresShell.cpp b/mozilla/layout/html/base/src/nsPresShell.cpp index 66ab0dfe425..6300e14f66c 100644 --- a/mozilla/layout/html/base/src/nsPresShell.cpp +++ b/mozilla/layout/html/base/src/nsPresShell.cpp @@ -7064,7 +7064,8 @@ PresShell::VerifyIncrementalReflow() NS_ASSERTION(NS_SUCCEEDED (rv), "failed to create presentation context"); nsCOMPtr dc; mPresContext->GetDeviceContext(getter_AddRefs(dc)); - cx->Init(dc); + rv = cx->Init(dc); + NS_ENSURE_SUCCESS(rv, rv); // Get our scrolling preference nsScrollPreference scrolling; diff --git a/mozilla/layout/html/base/src/nsTextFrame.cpp b/mozilla/layout/html/base/src/nsTextFrame.cpp index 5f846f50355..580ea011140 100644 --- a/mozilla/layout/html/base/src/nsTextFrame.cpp +++ b/mozilla/layout/html/base/src/nsTextFrame.cpp @@ -568,12 +568,11 @@ public: // Get colors from look&feel mSelectionBGColor = NS_RGB(0, 0, 0); mSelectionTextColor = NS_RGB(255, 255, 255); - nsILookAndFeel* look = nsnull; - if (NS_SUCCEEDED(aPresContext->GetLookAndFeel(&look)) && look) { - look->GetColor(nsILookAndFeel::eColor_TextSelectBackground, mSelectionBGColor); - look->GetColor(nsILookAndFeel::eColor_TextSelectForeground, mSelectionTextColor); - NS_RELEASE(look); - } + nsILookAndFeel* look = aPresContext->LookAndFeel(); + look->GetColor(nsILookAndFeel::eColor_TextSelectBackground, + mSelectionBGColor); + look->GetColor(nsILookAndFeel::eColor_TextSelectForeground, + mSelectionTextColor); // Get the word and letter spacing mWordSpacing = 0; @@ -1021,15 +1020,15 @@ DrawSelectionIterator::DrawSelectionIterator(nsIContent *aContent, } // Get background colors for disabled selection at attention-getting selection (used with type ahead find) - nsCOMPtr look; - if (NS_SUCCEEDED(aPresContext->GetLookAndFeel(getter_AddRefs(look))) && look) { - look->GetColor(nsILookAndFeel::eColor_TextSelectBackgroundAttention, mAttentionColor); - look->GetColor(nsILookAndFeel::eColor_TextSelectBackgroundDisabled, mDisabledColor); - mDisabledColor = EnsureDifferentColors(mDisabledColor, mOldStyle.mSelectionBGColor); - mAttentionColor = EnsureDifferentColors(mAttentionColor, mOldStyle.mSelectionBGColor); - } - else - mDisabledColor = mAttentionColor = mOldStyle.mSelectionBGColor; + nsILookAndFeel *look = aPresContext->LookAndFeel(); + look->GetColor(nsILookAndFeel::eColor_TextSelectBackgroundAttention, + mAttentionColor); + look->GetColor(nsILookAndFeel::eColor_TextSelectBackgroundDisabled, + mDisabledColor); + mDisabledColor = EnsureDifferentColors(mDisabledColor, + mOldStyle.mSelectionBGColor); + mAttentionColor = EnsureDifferentColors(mAttentionColor, + mOldStyle.mSelectionBGColor); if (!aSelDetails) { diff --git a/mozilla/layout/html/forms/src/nsFormControlFrame.cpp b/mozilla/layout/html/forms/src/nsFormControlFrame.cpp index 00c69c2e1ba..563c39dcd9a 100644 --- a/mozilla/layout/html/forms/src/nsFormControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsFormControlFrame.cpp @@ -871,10 +871,9 @@ nsFormControlFrame::GetScreenHeight(nsIPresContext* aPresContext, nscoord& aHeig nsRect screen; PRBool dropdownCanOverlapOSBar = PR_FALSE; - nsCOMPtr lookAndFeel; - aPresContext->GetLookAndFeel(getter_AddRefs(lookAndFeel)); - if ( lookAndFeel ) - lookAndFeel->GetMetric(nsILookAndFeel::eMetric_MenusCanOverlapOSBar, dropdownCanOverlapOSBar); + nsILookAndFeel *lookAndFeel = aPresContext->LookAndFeel(); + lookAndFeel->GetMetric(nsILookAndFeel::eMetric_MenusCanOverlapOSBar, + dropdownCanOverlapOSBar); if ( dropdownCanOverlapOSBar ) context->GetRect ( screen ); else diff --git a/mozilla/layout/html/forms/src/nsListControlFrame.cpp b/mozilla/layout/html/forms/src/nsListControlFrame.cpp index 1189a4b952c..742e158716b 100644 --- a/mozilla/layout/html/forms/src/nsListControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsListControlFrame.cpp @@ -84,7 +84,6 @@ #include "nsISelectElement.h" #include "nsIPrivateDOMEvent.h" #include "nsCSSRendering.h" -#include "nsILookAndFeel.h" #include "nsReflowPath.h" #include "nsITheme.h" #include "nsIDOMMouseListener.h" @@ -689,14 +688,10 @@ void nsListControlFrame::PaintFocus(nsIRenderingContext& aRC, nsFramePaintLayer // set up back stop colors and then ask L&F service for the real colors nscolor color; - nsCOMPtr lookAndFeel; - mPresContext->GetLookAndFeel(getter_AddRefs(lookAndFeel)); - if (lookAndFeel){ - lookAndFeel->GetColor(lastItemIsSelected?nsILookAndFeel::eColor_WidgetSelectForeground:nsILookAndFeel::eColor_WidgetSelectBackground, color); - } else { - // Use some backstop colors if for some reason we don't have a L&F object - color = lastItemIsSelected? NS_RGB(245,219,149) : NS_RGB(0,0,0); - } + mPresContext->LookAndFeel()-> + GetColor(lastItemIsSelected ? + nsILookAndFeel::eColor_WidgetSelectForeground : + nsILookAndFeel::eColor_WidgetSelectBackground, color); float p2t; mPresContext->GetScaledPixelsToTwips(&p2t); diff --git a/mozilla/layout/html/table/src/nsTableCellFrame.cpp b/mozilla/layout/html/table/src/nsTableCellFrame.cpp index 8d763c1d7bf..141c740b33a 100644 --- a/mozilla/layout/html/table/src/nsTableCellFrame.cpp +++ b/mozilla/layout/html/table/src/nsTableCellFrame.cpp @@ -344,11 +344,9 @@ nsTableCellFrame::DecorateForSelection(nsIPresContext* aPresContext, bordercolor = NS_RGB(176,176,176);// disabled color } else { - nsILookAndFeel* look = nsnull; - if (NS_SUCCEEDED(aPresContext->GetLookAndFeel(&look)) && look) { - look->GetColor(nsILookAndFeel::eColor_TextSelectBackground, bordercolor); - NS_RELEASE(look); - } + aPresContext->LookAndFeel()-> + GetColor(nsILookAndFeel::eColor_TextSelectBackground, + bordercolor); } float t2pfloat; if (NS_SUCCEEDED(aPresContext->GetPixelsToTwips(&t2pfloat))) diff --git a/mozilla/layout/mathml/base/src/nsMathMLChar.cpp b/mozilla/layout/mathml/base/src/nsMathMLChar.cpp index a806cd5b601..d7b5f378fd9 100644 --- a/mozilla/layout/mathml/base/src/nsMathMLChar.cpp +++ b/mozilla/layout/mathml/base/src/nsMathMLChar.cpp @@ -1953,14 +1953,11 @@ nsMathMLChar::Paint(nsIPresContext* aPresContext, // paint the selection background -- beware MathML frames overlap a lot if (aSelectedRect && !aSelectedRect->IsEmpty()) { // get color to use for selection from the look&feel object - nsCOMPtr lf; - aPresContext->GetLookAndFeel(getter_AddRefs(lf)); - if (lf) { - nscolor bgColor = NS_RGB(0, 0, 0); - lf->GetColor(nsILookAndFeel::eColor_TextSelectBackground, bgColor); - aRenderingContext.SetColor(bgColor); - aRenderingContext.FillRect(*aSelectedRect); - } + nscolor bgColor = NS_RGB(0, 0, 0); + aPresContext->LookAndFeel()-> + GetColor(nsILookAndFeel::eColor_TextSelectBackground, bgColor); + aRenderingContext.SetColor(bgColor); + aRenderingContext.FillRect(*aSelectedRect); } else if (mRect.width && mRect.height) { const nsStyleBorder* border = styleContext->GetStyleBorder(); @@ -1993,11 +1990,8 @@ nsMathMLChar::Paint(nsIPresContext* aPresContext, nscolor fgColor = styleContext->GetStyleColor()->mColor; if (aSelectedRect && !aSelectedRect->IsEmpty()) { // get color to use for selection from the look&feel object - nsCOMPtr lf; - aPresContext->GetLookAndFeel(getter_AddRefs(lf)); - if (lf) { - lf->GetColor(nsILookAndFeel::eColor_TextSelectForeground, fgColor); - } + aPresContext->LookAndFeel()-> + GetColor(nsILookAndFeel::eColor_TextSelectForeground, fgColor); } aRenderingContext.SetColor(fgColor); diff --git a/mozilla/layout/printing/nsPrintEngine.cpp b/mozilla/layout/printing/nsPrintEngine.cpp index 81b09f6c70f..d02ac9d3c17 100644 --- a/mozilla/layout/printing/nsPrintEngine.cpp +++ b/mozilla/layout/printing/nsPrintEngine.cpp @@ -2603,7 +2603,11 @@ nsPrintEngine::ReflowPrintObject(nsPrintObject * aPO, PRBool aDoCalcShrink) // init it with the DC - (aPO->mPresContext)->Init(mPrt->mPrintDocDC); + rv = aPO->mPresContext->Init(mPrt->mPrintDocDC); + if (NS_FAILED(rv)) { + aPO->mPresContext = nsnull; + return rv; + } rv = mDocViewerPrint->CreateStyleSet(aPO->mDocument, &aPO->mStyleSet); NS_ENSURE_SUCCESS(rv, rv); diff --git a/mozilla/layout/style/nsRuleNode.cpp b/mozilla/layout/style/nsRuleNode.cpp index bcdd22b9440..1239a8eddfa 100644 --- a/mozilla/layout/style/nsRuleNode.cpp +++ b/mozilla/layout/style/nsRuleNode.cpp @@ -330,13 +330,10 @@ static PRBool SetColor(const nsCSSValue& aValue, const nscolor aParentColor, else if (eCSSUnit_Integer == unit) { PRInt32 intValue = aValue.GetIntValue(); if (0 <= intValue) { - nsILookAndFeel* look = nsnull; - if (NS_SUCCEEDED(aPresContext->GetLookAndFeel(&look)) && look) { - nsILookAndFeel::nsColorID colorID = (nsILookAndFeel::nsColorID) intValue; - if (NS_SUCCEEDED(look->GetColor(colorID, aResult))) { - result = PR_TRUE; - } - NS_RELEASE(look); + nsILookAndFeel* look = aPresContext->LookAndFeel(); + nsILookAndFeel::nsColorID colorID = (nsILookAndFeel::nsColorID) intValue; + if (NS_SUCCEEDED(look->GetColor(colorID, aResult))) { + result = PR_TRUE; } } else { diff --git a/mozilla/layout/tables/nsTableCellFrame.cpp b/mozilla/layout/tables/nsTableCellFrame.cpp index 8d763c1d7bf..141c740b33a 100644 --- a/mozilla/layout/tables/nsTableCellFrame.cpp +++ b/mozilla/layout/tables/nsTableCellFrame.cpp @@ -344,11 +344,9 @@ nsTableCellFrame::DecorateForSelection(nsIPresContext* aPresContext, bordercolor = NS_RGB(176,176,176);// disabled color } else { - nsILookAndFeel* look = nsnull; - if (NS_SUCCEEDED(aPresContext->GetLookAndFeel(&look)) && look) { - look->GetColor(nsILookAndFeel::eColor_TextSelectBackground, bordercolor); - NS_RELEASE(look); - } + aPresContext->LookAndFeel()-> + GetColor(nsILookAndFeel::eColor_TextSelectBackground, + bordercolor); } float t2pfloat; if (NS_SUCCEEDED(aPresContext->GetPixelsToTwips(&t2pfloat))) diff --git a/mozilla/layout/xul/base/src/nsMenuPopupFrame.cpp b/mozilla/layout/xul/base/src/nsMenuPopupFrame.cpp index efe1cc6e284..db9a094227c 100644 --- a/mozilla/layout/xul/base/src/nsMenuPopupFrame.cpp +++ b/mozilla/layout/xul/base/src/nsMenuPopupFrame.cpp @@ -78,8 +78,6 @@ #include "nsISound.h" #endif -static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); - const PRInt32 kMaxZ = 0x7fffffff; //XXX: Shouldn't there be a define somewhere for MaxInt for PRInt32 @@ -173,13 +171,10 @@ nsMenuPopupFrame::Init(nsIPresContext* aPresContext, // lookup if we're allowed to overlap the OS bar (menubar/taskbar) from the // look&feel object - nsCOMPtr lookAndFeel; - aPresContext->GetLookAndFeel(getter_AddRefs(lookAndFeel)); - if ( lookAndFeel ) { - PRBool tempBool; - lookAndFeel->GetMetric(nsILookAndFeel::eMetric_MenusCanOverlapOSBar, tempBool); - mMenuCanOverlapOSBar = tempBool; - } + PRBool tempBool; + aPresContext->LookAndFeel()-> + GetMetric(nsILookAndFeel::eMetric_MenusCanOverlapOSBar, tempBool); + mMenuCanOverlapOSBar = tempBool; // XXX Hack mPresContext = aPresContext; @@ -1481,12 +1476,8 @@ NS_IMETHODIMP nsMenuPopupFrame::SetCurrentMenuItem(nsIMenuFrame* aMenuItem) KillCloseTimer(); // Ensure we don't have another stray waiting closure. PRInt32 menuDelay = 300; // ms - nsILookAndFeel * lookAndFeel; - if (NS_OK == nsComponentManager::CreateInstance(kLookAndFeelCID, nsnull, - NS_GET_IID(nsILookAndFeel), (void**)&lookAndFeel)) { - lookAndFeel->GetMetric(nsILookAndFeel::eMetric_SubmenuDelay, menuDelay); - NS_RELEASE(lookAndFeel); - } + mPresContext->LookAndFeel()-> + GetMetric(nsILookAndFeel::eMetric_SubmenuDelay, menuDelay); // Kick off the timer. mCloseTimer = do_CreateInstance("@mozilla.org/timer;1"); diff --git a/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp b/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp index b76bae42701..eac8fb8b6f7 100644 --- a/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp +++ b/mozilla/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp @@ -1655,10 +1655,7 @@ nsTreeBodyFrame::CreateTimer(const nsILookAndFeel::nsMetricID aID, // Get the delay from the look and feel service. PRInt32 delay = 0; nsCOMPtr lookAndFeel; - mPresContext->GetLookAndFeel(getter_AddRefs(lookAndFeel)); - if (lookAndFeel) { - lookAndFeel->GetMetric(aID, delay); - } + mPresContext->LookAndFeel()->GetMetric(aID, delay); nsCOMPtr timer; @@ -3758,15 +3755,11 @@ nsTreeBodyFrame::ComputeDropPosition(nsIDOMEvent* aEvent, PRInt32* aRow, PRInt16 if (CanAutoScroll(*aRow)) { // Get the max value from the look and feel service. PRInt32 scrollLinesMax = 0; - nsCOMPtr lookAndFeel; - mPresContext->GetLookAndFeel(getter_AddRefs(lookAndFeel)); - if (lookAndFeel) { - lookAndFeel->GetMetric(nsILookAndFeel::eMetric_TreeScrollLinesMax, - scrollLinesMax); - scrollLinesMax--; - if (scrollLinesMax < 0) - scrollLinesMax = 0; - } + mPresContext->LookAndFeel()-> + GetMetric(nsILookAndFeel::eMetric_TreeScrollLinesMax, scrollLinesMax); + scrollLinesMax--; + if (scrollLinesMax < 0) + scrollLinesMax = 0; // Determine if we're w/in a margin of the top/bottom of the tree during a drag. // This will ultimately cause us to scroll, but that's done elsewhere.