diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp index 29fb53a3da89..df99ea0b1e43 100644 --- a/layout/base/nsPresContext.cpp +++ b/layout/base/nsPresContext.cpp @@ -36,6 +36,9 @@ #include "nsIDocument.h" #include "nsIStyleContext.h" #include "nsLayoutAtoms.h" +#include "nsILookAndFeel.h" +#include "nsWidgetsCID.h" +#include "nsIComponentManager.h" #ifdef _WIN32 #include #endif @@ -53,6 +56,8 @@ PrefChangedCallback(const char* aPrefName, void* instance_data) } static NS_DEFINE_IID(kIPresContextIID, NS_IPRESCONTEXT_IID); +static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); +static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID); nsPresContext::nsPresContext() : mDefaultFont("Times", NS_FONT_STYLE_NORMAL, @@ -76,7 +81,8 @@ nsPresContext::nsPresContext() #else mWidgetRenderingMode = eWidgetRendering_Gfx; #endif - + + mLookAndFeel = nsnull; #ifdef _WIN32 // XXX This needs to be elsewhere, e.g., part of nsIDeviceContext @@ -106,6 +112,8 @@ nsPresContext::~nsPresContext() if (mEventManager) mEventManager->SetPresContext(nsnull); // unclear if this is needed, but can't hurt + NS_IF_RELEASE(mLookAndFeel); + // Unregister preference callbacks if (mPrefs) { mPrefs->UnregisterCallback("browser.", PrefChangedCallback, (void*)this); @@ -368,6 +376,28 @@ nsPresContext::SetWidgetRenderingMode(nsWidgetRendering aMode) } +NS_IMETHODIMP +nsPresContext::GetLookAndFeel(nsILookAndFeel** aLookAndFeel) +{ + NS_PRECONDITION(nsnull != aLookAndFeel, "null ptr"); + if (nsnull == aLookAndFeel) { + return NS_ERROR_NULL_POINTER; + } + nsresult result = NS_OK; + if (! mLookAndFeel) { + result = nsComponentManager::CreateInstance(kLookAndFeelCID, nsnull, + kILookAndFeelIID, (void**)&mLookAndFeel); + if (NS_FAILED(result)) { + mLookAndFeel = nsnull; + } + } + NS_IF_ADDREF(mLookAndFeel); + *aLookAndFeel = mLookAndFeel; + return result; +} + + + NS_IMETHODIMP nsPresContext::GetBaseURL(nsIURI** aResult) { diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h index eaff77e77ebb..d321aa42030f 100644 --- a/layout/base/nsPresContext.h +++ b/layout/base/nsPresContext.h @@ -41,6 +41,7 @@ class nsIAtom; class nsString; class nsIEventStateManager; class nsIURI; +class nsILookAndFeel; #define NS_IPRESCONTEXT_IID \ { 0x0a5d12e0, 0x944e, 0x11d1, \ @@ -108,6 +109,11 @@ public: NS_IMETHOD GetWidgetRenderingMode(nsWidgetRendering* aModeResult) = 0; NS_IMETHOD SetWidgetRenderingMode(nsWidgetRendering aMode) = 0; + /** + * Get look and feel object + */ + NS_IMETHOD GetLookAndFeel(nsILookAndFeel** aLookAndFeel) = 0; + /** * Get base url for presentation */ diff --git a/layout/base/public/nsIPresContext.h b/layout/base/public/nsIPresContext.h index eaff77e77ebb..d321aa42030f 100644 --- a/layout/base/public/nsIPresContext.h +++ b/layout/base/public/nsIPresContext.h @@ -41,6 +41,7 @@ class nsIAtom; class nsString; class nsIEventStateManager; class nsIURI; +class nsILookAndFeel; #define NS_IPRESCONTEXT_IID \ { 0x0a5d12e0, 0x944e, 0x11d1, \ @@ -108,6 +109,11 @@ public: NS_IMETHOD GetWidgetRenderingMode(nsWidgetRendering* aModeResult) = 0; NS_IMETHOD SetWidgetRenderingMode(nsWidgetRendering aMode) = 0; + /** + * Get look and feel object + */ + NS_IMETHOD GetLookAndFeel(nsILookAndFeel** aLookAndFeel) = 0; + /** * Get base url for presentation */ diff --git a/layout/base/public/nsPresContext.h b/layout/base/public/nsPresContext.h index eaff77e77ebb..d321aa42030f 100644 --- a/layout/base/public/nsPresContext.h +++ b/layout/base/public/nsPresContext.h @@ -41,6 +41,7 @@ class nsIAtom; class nsString; class nsIEventStateManager; class nsIURI; +class nsILookAndFeel; #define NS_IPRESCONTEXT_IID \ { 0x0a5d12e0, 0x944e, 0x11d1, \ @@ -108,6 +109,11 @@ public: NS_IMETHOD GetWidgetRenderingMode(nsWidgetRendering* aModeResult) = 0; NS_IMETHOD SetWidgetRenderingMode(nsWidgetRendering aMode) = 0; + /** + * Get look and feel object + */ + NS_IMETHOD GetLookAndFeel(nsILookAndFeel** aLookAndFeel) = 0; + /** * Get base url for presentation */ diff --git a/layout/base/src/nsPresContext.cpp b/layout/base/src/nsPresContext.cpp index 29fb53a3da89..df99ea0b1e43 100644 --- a/layout/base/src/nsPresContext.cpp +++ b/layout/base/src/nsPresContext.cpp @@ -36,6 +36,9 @@ #include "nsIDocument.h" #include "nsIStyleContext.h" #include "nsLayoutAtoms.h" +#include "nsILookAndFeel.h" +#include "nsWidgetsCID.h" +#include "nsIComponentManager.h" #ifdef _WIN32 #include #endif @@ -53,6 +56,8 @@ PrefChangedCallback(const char* aPrefName, void* instance_data) } static NS_DEFINE_IID(kIPresContextIID, NS_IPRESCONTEXT_IID); +static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); +static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID); nsPresContext::nsPresContext() : mDefaultFont("Times", NS_FONT_STYLE_NORMAL, @@ -76,7 +81,8 @@ nsPresContext::nsPresContext() #else mWidgetRenderingMode = eWidgetRendering_Gfx; #endif - + + mLookAndFeel = nsnull; #ifdef _WIN32 // XXX This needs to be elsewhere, e.g., part of nsIDeviceContext @@ -106,6 +112,8 @@ nsPresContext::~nsPresContext() if (mEventManager) mEventManager->SetPresContext(nsnull); // unclear if this is needed, but can't hurt + NS_IF_RELEASE(mLookAndFeel); + // Unregister preference callbacks if (mPrefs) { mPrefs->UnregisterCallback("browser.", PrefChangedCallback, (void*)this); @@ -368,6 +376,28 @@ nsPresContext::SetWidgetRenderingMode(nsWidgetRendering aMode) } +NS_IMETHODIMP +nsPresContext::GetLookAndFeel(nsILookAndFeel** aLookAndFeel) +{ + NS_PRECONDITION(nsnull != aLookAndFeel, "null ptr"); + if (nsnull == aLookAndFeel) { + return NS_ERROR_NULL_POINTER; + } + nsresult result = NS_OK; + if (! mLookAndFeel) { + result = nsComponentManager::CreateInstance(kLookAndFeelCID, nsnull, + kILookAndFeelIID, (void**)&mLookAndFeel); + if (NS_FAILED(result)) { + mLookAndFeel = nsnull; + } + } + NS_IF_ADDREF(mLookAndFeel); + *aLookAndFeel = mLookAndFeel; + return result; +} + + + NS_IMETHODIMP nsPresContext::GetBaseURL(nsIURI** aResult) { diff --git a/layout/base/src/nsPresContext.h b/layout/base/src/nsPresContext.h index 7474f8c24d12..1611c704d7dd 100644 --- a/layout/base/src/nsPresContext.h +++ b/layout/base/src/nsPresContext.h @@ -48,6 +48,7 @@ public: NS_IMETHOD SetCompatibilityMode(nsCompatibility aMode); NS_IMETHOD GetWidgetRenderingMode(nsWidgetRendering* aModeResult); NS_IMETHOD SetWidgetRenderingMode(nsWidgetRendering aMode); + NS_IMETHOD GetLookAndFeel(nsILookAndFeel** aLookAndFeel); NS_IMETHOD GetBaseURL(nsIURI** aURLResult); NS_IMETHOD GetMedium(nsIAtom** aMediumResult) = 0; NS_IMETHOD ResolveStyleContextFor(nsIContent* aContent, @@ -131,6 +132,7 @@ protected: nsCOMPtr mImageGroup; nsILinkHandler* mLinkHandler; // [WEAK] nsISupports* mContainer; // [WEAK] + nsILookAndFeel* mLookAndFeel; nsFont mDefaultFont; nsFont mDefaultFixedFont; PRInt32 mFontScaler;