зеркало из https://github.com/mozilla/pjs.git
using generic factory for nsViewManager creation, removed extraneous calls to AddRef/Release of created views.
This commit is contained in:
Родитель
e574cd2b26
Коммит
05f7f9f084
|
@ -17,7 +17,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "nscore.h"
|
#include "nscore.h"
|
||||||
#include "nsIFactory.h"
|
#include "nsIGenericFactory.h"
|
||||||
#include "nsISupports.h"
|
#include "nsISupports.h"
|
||||||
|
|
||||||
#include "nsViewsCID.h"
|
#include "nsViewsCID.h"
|
||||||
|
@ -62,40 +62,39 @@ NS_IMPL_ISUPPORTS1(nsViewFactory, nsIFactory)
|
||||||
nsresult nsViewFactory::CreateInstance(nsISupports *aOuter,
|
nsresult nsViewFactory::CreateInstance(nsISupports *aOuter,
|
||||||
const nsIID &aIID,
|
const nsIID &aIID,
|
||||||
void **aResult)
|
void **aResult)
|
||||||
{
|
{
|
||||||
if (aResult == NULL) {
|
nsresult rv = NS_OK;
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
}
|
|
||||||
|
|
||||||
*aResult = NULL;
|
if (aResult == NULL) {
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
nsISupports *inst = nsnull;
|
}
|
||||||
|
|
||||||
if (mClassID.Equals(kCViewManager)) {
|
*aResult = NULL;
|
||||||
inst = (nsISupports*) new nsViewManager();
|
|
||||||
} else if (mClassID.Equals(kCView)) {
|
|
||||||
inst = (nsISupports*) new nsView();
|
|
||||||
} else if (mClassID.Equals(kCScrollingView)) {
|
|
||||||
inst = (nsISupports*) (nsView*) new nsScrollingView();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inst == NULL) {
|
// views aren't reference counted, so have to be treated specially.
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
// their lifetimes are managed by the view manager they are associated with.
|
||||||
}
|
nsIView* view = nsnull;
|
||||||
|
if (mClassID.Equals(kCView)) {
|
||||||
// add a reference count,
|
view = new nsView();
|
||||||
NS_ADDREF(inst);
|
} else if (mClassID.Equals(kCScrollingView)) {
|
||||||
nsresult res = inst->QueryInterface(aIID, aResult);
|
view = new nsScrollingView();
|
||||||
NS_RELEASE(inst);
|
}
|
||||||
|
if (nsnull == view)
|
||||||
return res;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
rv = view->QueryInterface(aIID, aResult);
|
||||||
|
if (NS_FAILED(rv))
|
||||||
|
view->Destroy();
|
||||||
|
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult nsViewFactory::LockFactory(PRBool aLock)
|
nsresult nsViewFactory::LockFactory(PRBool aLock)
|
||||||
{
|
{
|
||||||
// Not implemented in simplest case.
|
// Not implemented in simplest case.
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsViewManager)
|
||||||
|
|
||||||
// return the proper factory to the caller
|
// return the proper factory to the caller
|
||||||
extern "C" NS_VIEW nsresult
|
extern "C" NS_VIEW nsresult
|
||||||
|
@ -105,15 +104,31 @@ NSGetFactory(nsISupports* serviceMgr,
|
||||||
const char *aProgID,
|
const char *aProgID,
|
||||||
nsIFactory **aFactory)
|
nsIFactory **aFactory)
|
||||||
{
|
{
|
||||||
if (nsnull == aFactory) {
|
nsresult rv;
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
}
|
|
||||||
|
|
||||||
*aFactory = new nsViewFactory(aClass);
|
do {
|
||||||
|
if (nsnull == aFactory) {
|
||||||
|
rv = NS_ERROR_NULL_POINTER;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (nsnull == aFactory) {
|
*aFactory = nsnull;
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (*aFactory)->QueryInterface(kIFactoryIID, (void**)aFactory);
|
if (aClass.Equals(kCViewManager)) {
|
||||||
|
nsIGenericFactory* factory = nsnull;
|
||||||
|
rv = NS_NewGenericFactory(&factory, &nsViewManagerConstructor);
|
||||||
|
if (NS_SUCCEEDED(rv))
|
||||||
|
*aFactory = factory;
|
||||||
|
} else if (aClass.Equals(kCView) || aClass.Equals(kCScrollingView)) {
|
||||||
|
nsViewFactory* factory = new nsViewFactory(aClass);
|
||||||
|
if (nsnull == factory) {
|
||||||
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
NS_ADDREF(factory);
|
||||||
|
*aFactory = factory;
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче