зеркало из https://github.com/mozilla/pjs.git
Fixed nsICollection (and Count in particular) to be xpidl friendly.
This commit is contained in:
Родитель
eaa7a6bea1
Коммит
7a41ef7d73
|
@ -1,231 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsIScriptable.h"
|
||||
#include "nscore.h"
|
||||
#include "xptcall.h"
|
||||
#include "nsIInterfaceInfoManager.h"
|
||||
|
||||
class nsScriptable : public nsIScriptable {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIProperties methods:
|
||||
NS_IMETHOD DefineProperty(const char* prop, nsISupports* initialValue);
|
||||
NS_IMETHOD UndefineProperty(const char* prop);
|
||||
NS_IMETHOD GetProperty(const char* prop, nsISupports* *result);
|
||||
NS_IMETHOD SetProperty(const char* prop, nsISupports* value);
|
||||
NS_IMETHOD HasProperty(const char* prop, nsISupports* value);
|
||||
|
||||
// nsIScriptable methods:
|
||||
NS_IMETHOD Call(const char* command,
|
||||
nsISupportsArray* arguments,
|
||||
nsISupports* *result);
|
||||
|
||||
// nsScriptable methods:
|
||||
nsScriptable(REFNSIID iid, nsISupports* object);
|
||||
virtual ~nsScriptable();
|
||||
|
||||
nsresult Init();
|
||||
// XXX should this be a method on nsIScriptable?
|
||||
NS_IMETHOD QueryInterfaceScriptable(REFNSIID aIID, void** aInstancePtr);
|
||||
|
||||
// XXX later this will be a service
|
||||
static nsIInterfaceInfoManager* gInterfaceInfoManager;
|
||||
|
||||
protected:
|
||||
nsISupports* mObject;
|
||||
nsIInterfaceInfo* mInterfaceInfo;
|
||||
nsID mIID;
|
||||
// nsXPCWrappedNativeClass* mClazz;
|
||||
// nsXPCWrappedNative* mWrapper;
|
||||
};
|
||||
|
||||
// XXX later this will be a service
|
||||
nsIInterfaceInfoManager* nsScriptable::gInterfaceInfoManager = nsnull;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsScriptable::nsScriptable(REFNSIID iid, nsISupports* object)
|
||||
: mObject(object), mInterfaceInfo(nsnull), mIID(iid)
|
||||
// , mClazz(nsnull), mWrapper(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF(mObject);
|
||||
}
|
||||
|
||||
nsScriptable::~nsScriptable()
|
||||
{
|
||||
NS_RELEASE(mObject);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsScriptable, nsIScriptable::GetIID());
|
||||
|
||||
nsresult
|
||||
nsScriptable::Init()
|
||||
{
|
||||
nsresult rv;
|
||||
if (gInterfaceInfoManager == nsnull) {
|
||||
gInterfaceInfoManager = XPTI_GetInterfaceInfoManager();
|
||||
if (gInterfaceInfoManager == nsnull)
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// get the interface info
|
||||
NS_IF_RELEASE(mInterfaceInfo);
|
||||
rv = gInterfaceInfoManager->GetInfoForIID(&mIID, &mInterfaceInfo);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIProperties methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScriptable::DefineProperty(const char* prop, nsISupports* initialValue)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScriptable::UndefineProperty(const char* prop)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScriptable::GetProperty(const char* prop, nsISupports* *result)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScriptable::SetProperty(const char* prop, nsISupports* value)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScriptable::HasProperty(const char* prop, nsISupports* expectedValue)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIScriptable methods:
|
||||
|
||||
#define PARAM_BUFFER_COUNT 16
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScriptable::Call(const char* methodName,
|
||||
nsISupportsArray* arguments,
|
||||
nsISupports* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
const nsXPTMethodInfo* methodInfo;
|
||||
PRUint16 vtblIndex;
|
||||
PRUint8 paramCount = arguments->Count();
|
||||
nsXPTCVariant paramBuffer[PARAM_BUFFER_COUNT];
|
||||
nsXPTCVariant* dispatchParams;
|
||||
PRUint8 requiredArgs;
|
||||
|
||||
// get the method info and vtable index
|
||||
rv = mInterfaceInfo->GetMethodInfoForName(methodName, &vtblIndex, &methodInfo);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (paramCount < PARAM_BUFFER_COUNT) {
|
||||
dispatchParams = paramBuffer;
|
||||
}
|
||||
else {
|
||||
dispatchParams = new nsXPTCVariant[paramCount];
|
||||
if (dispatchParams == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// put together the parameter list
|
||||
for (PRUint8 i = 0; i < paramCount; i++) {
|
||||
nsISupports* arg = (*arguments)[i];
|
||||
const nsXPTParamInfo& paramInfo = methodInfo->GetParam(i);
|
||||
const nsXPTType& paramType = paramInfo.GetType();
|
||||
nsXPTCVariant* dp = &dispatchParams[i];
|
||||
|
||||
if (paramInfo.IsOut()) {
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
switch (paramType.TagPart()) {
|
||||
case nsXPTType::T_INTERFACE:
|
||||
dp->flags |= nsXPTCVariant::VAL_IS_IFACE;
|
||||
nsID* iid;
|
||||
rv = mInterfaceInfo->GetIIDForParam(¶mInfo, &iid);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
break;
|
||||
case nsXPTType::T_INTERFACE_IS:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// invoke the method
|
||||
rv = XPTC_InvokeByIndex(mObject, vtblIndex, paramCount, dispatchParams);
|
||||
// return any out parameters
|
||||
|
||||
done:
|
||||
if (dispatchParams != paramBuffer)
|
||||
delete[] dispatchParams;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScriptable::QueryInterfaceScriptable(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
NS_PRECONDITION(aInstancePtr, "null aInstancePtr");
|
||||
nsresult rv;
|
||||
rv = mObject->QueryInterface(aIID, aInstancePtr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
NS_RELEASE(mObject);
|
||||
mObject = *(nsISupports**)aInstancePtr;
|
||||
mIID = aIID;
|
||||
return Init();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern nsresult
|
||||
NS_NewIScriptable(REFNSIID iid, nsISupports* object, nsIScriptable* *result)
|
||||
{
|
||||
nsScriptable* s = new nsScriptable(iid, object);
|
||||
if (s == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
nsresult rv = s->Init();
|
||||
if (NS_FAILED(rv)) {
|
||||
delete s;
|
||||
return rv;
|
||||
}
|
||||
NS_ADDREF(s);
|
||||
*result = s;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
|
@ -1,477 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsThread.h"
|
||||
#include "prmem.h"
|
||||
//#include <stdio.h>
|
||||
|
||||
PRUintn nsThread::kIThreadSelfIndex = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsThread::nsThread()
|
||||
: mThread(nsnull), mRunnable(nsnull), mDead(PR_FALSE)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsThread::Init(nsIRunnable* runnable,
|
||||
PRUint32 stackSize,
|
||||
PRThreadPriority priority,
|
||||
PRThreadScope scope,
|
||||
PRThreadState state)
|
||||
{
|
||||
mRunnable = runnable;
|
||||
NS_ADDREF(mRunnable);
|
||||
|
||||
NS_ADDREF_THIS(); // released in nsThread::Exit
|
||||
if (state == PR_JOINABLE_THREAD)
|
||||
NS_ADDREF_THIS(); // released in nsThread::Join
|
||||
mThread = PR_CreateThread(PR_USER_THREAD, Main, this,
|
||||
priority, scope, state, stackSize);
|
||||
// printf("%x %x (%d) create\n", this, mThread, mRefCnt);
|
||||
if (mThread == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsThread::~nsThread()
|
||||
{
|
||||
// printf("%x %x (%d) destroy\n", this, mThread, mRefCnt);
|
||||
NS_IF_RELEASE(mRunnable);
|
||||
}
|
||||
|
||||
void
|
||||
nsThread::Main(void* arg)
|
||||
{
|
||||
nsThread* self = (nsThread*)arg;
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
rv = self->RegisterThreadSelf();
|
||||
NS_ASSERTION(rv == NS_OK, "failed to set thread self");
|
||||
|
||||
// printf("%x %x (%d) start run\n", self, self->mThread, self->mRefCnt);
|
||||
rv = self->mRunnable->Run();
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "runnable failed");
|
||||
|
||||
PRThreadState state;
|
||||
rv = self->GetState(&state);
|
||||
// printf("%x %x (%d) end run\n", self, self->mThread, self->mRefCnt);
|
||||
}
|
||||
|
||||
void
|
||||
nsThread::Exit(void* arg)
|
||||
{
|
||||
nsThread* self = (nsThread*)arg;
|
||||
nsresult rv = NS_OK;
|
||||
self->mDead = PR_TRUE;
|
||||
// printf("%x %x (%d) exit\n", self, self->mThread, self->mRefCnt - 1);
|
||||
NS_RELEASE(self);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsThread, nsIThread::GetIID());
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsThread::Join()
|
||||
{
|
||||
// don't check for mDead here because nspr calls Exit (cleaning up
|
||||
// thread-local storage) before they let us join with the thread
|
||||
|
||||
// printf("%x %x (%d) start join\n", this, mThread, mRefCnt);
|
||||
PRStatus status = PR_JoinThread(mThread);
|
||||
// XXX can't use NS_RELEASE here because the macro wants to set
|
||||
// this to null (bad c++)
|
||||
// printf("%x %x (%d) end join\n", this, mThread, mRefCnt);
|
||||
if (status == PR_SUCCESS) {
|
||||
this->Release(); // most likely the final release of this thread
|
||||
return NS_OK;
|
||||
}
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsThread::GetPriority(PRThreadPriority *result)
|
||||
{
|
||||
if (mDead)
|
||||
return NS_ERROR_FAILURE;
|
||||
*result = PR_GetThreadPriority(mThread);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsThread::SetPriority(PRThreadPriority value)
|
||||
{
|
||||
if (mDead)
|
||||
return NS_ERROR_FAILURE;
|
||||
PR_SetThreadPriority(mThread, value);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsThread::Interrupt()
|
||||
{
|
||||
if (mDead)
|
||||
return NS_ERROR_FAILURE;
|
||||
PRStatus status = PR_Interrupt(mThread);
|
||||
return status == PR_SUCCESS ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsThread::GetScope(PRThreadScope *result)
|
||||
{
|
||||
if (mDead)
|
||||
return NS_ERROR_FAILURE;
|
||||
*result = PR_GetThreadScope(mThread);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsThread::GetState(PRThreadState *result)
|
||||
{
|
||||
if (mDead)
|
||||
return NS_ERROR_FAILURE;
|
||||
*result = PR_GetThreadState(mThread);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsThread::GetPRThread(PRThread* *result)
|
||||
{
|
||||
if (mDead)
|
||||
return NS_ERROR_FAILURE;
|
||||
*result = mThread;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_BASE nsresult
|
||||
NS_NewThread(nsIThread* *result,
|
||||
nsIRunnable* runnable,
|
||||
PRUint32 stackSize,
|
||||
PRThreadPriority priority,
|
||||
PRThreadScope scope,
|
||||
PRThreadState state)
|
||||
{
|
||||
nsresult rv;
|
||||
nsThread* thread = new nsThread();
|
||||
if (thread == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
rv = thread->Init(runnable, stackSize, priority, scope, state);
|
||||
if (NS_FAILED(rv)) {
|
||||
delete thread;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_ADDREF(thread);
|
||||
*result = thread;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult
|
||||
nsThread::RegisterThreadSelf()
|
||||
{
|
||||
PRStatus status;
|
||||
|
||||
if (kIThreadSelfIndex == 0) {
|
||||
status = PR_NewThreadPrivateIndex(&kIThreadSelfIndex, Exit);
|
||||
if (status != PR_SUCCESS) return NS_ERROR_FAILURE;
|
||||
NS_ASSERTION(kIThreadSelfIndex != 0, "couldn't get thread private index");
|
||||
}
|
||||
|
||||
status = PR_SetThreadPrivate(kIThreadSelfIndex, this);
|
||||
if (status != PR_SUCCESS) return NS_ERROR_FAILURE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_BASE nsresult
|
||||
nsIThread::GetCurrent(nsIThread* *result)
|
||||
{
|
||||
return GetIThread(PR_CurrentThread(), result);
|
||||
}
|
||||
|
||||
NS_BASE nsresult
|
||||
nsIThread::GetIThread(PRThread* prthread, nsIThread* *result)
|
||||
{
|
||||
PRStatus status;
|
||||
nsThread* thread;
|
||||
|
||||
if (nsThread::kIThreadSelfIndex == 0) {
|
||||
status = PR_NewThreadPrivateIndex(&nsThread::kIThreadSelfIndex, nsThread::Exit);
|
||||
if (status != PR_SUCCESS) return NS_ERROR_FAILURE;
|
||||
NS_ASSERTION(nsThread::kIThreadSelfIndex != 0, "couldn't get thread private index");
|
||||
}
|
||||
|
||||
thread = (nsThread*)PR_GetThreadPrivate(nsThread::kIThreadSelfIndex);
|
||||
if (thread == nsnull) {
|
||||
// if the current thread doesn't have an nsIThread associated
|
||||
// with it, make one
|
||||
thread = new nsThread();
|
||||
if (thread == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(thread);
|
||||
thread->SetPRThread(prthread);
|
||||
nsresult rv = thread->RegisterThreadSelf();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
NS_ADDREF(thread);
|
||||
*result = thread;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsThreadPool::nsThreadPool(PRUint32 minThreads, PRUint32 maxThreads)
|
||||
: mThreads(nsnull), mRequests(nsnull),
|
||||
mMinThreads(minThreads), mMaxThreads(maxThreads), mShuttingDown(PR_FALSE)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsThreadPool::Init(PRUint32 stackSize,
|
||||
PRThreadPriority priority,
|
||||
PRThreadScope scope)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
rv = NS_NewISupportsArray(&mThreads);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = NS_NewISupportsArray(&mRequests);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
mRequestMonitor = PR_NewMonitor();
|
||||
if (mRequestMonitor == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
PR_CEnterMonitor(this);
|
||||
|
||||
for (PRUint32 i = 0; i < mMinThreads; i++) {
|
||||
nsThreadPoolRunnable* runnable =
|
||||
new nsThreadPoolRunnable(this);
|
||||
if (runnable == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(runnable);
|
||||
|
||||
nsIThread* thread;
|
||||
|
||||
rv = NS_NewThread(&thread, runnable, stackSize, priority, scope,
|
||||
PR_JOINABLE_THREAD); // needed for Shutdown
|
||||
NS_RELEASE(runnable);
|
||||
if (NS_FAILED(rv)) goto exit;
|
||||
|
||||
rv = mThreads->AppendElement(thread) ? NS_OK : NS_ERROR_FAILURE;
|
||||
NS_RELEASE(thread);
|
||||
if (NS_FAILED(rv)) goto exit;
|
||||
}
|
||||
// wait for some worker thread to be ready
|
||||
PR_CWait(this, PR_INTERVAL_NO_TIMEOUT);
|
||||
|
||||
exit:
|
||||
PR_CExitMonitor(this);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsThreadPool::~nsThreadPool()
|
||||
{
|
||||
if (mThreads) {
|
||||
Shutdown();
|
||||
NS_RELEASE(mThreads);
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(mRequests);
|
||||
|
||||
if (mRequestMonitor) {
|
||||
PR_DestroyMonitor(mRequestMonitor);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsThreadPool, nsIThreadPool::GetIID());
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsThreadPool::DispatchRequest(nsIRunnable* runnable)
|
||||
{
|
||||
nsresult rv;
|
||||
PR_EnterMonitor(mRequestMonitor);
|
||||
|
||||
if (mShuttingDown) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
else {
|
||||
// XXX for now AppendElement returns a PRBool
|
||||
rv = ((PRBool) mRequests->AppendElement(runnable)) ? NS_OK : NS_ERROR_FAILURE;
|
||||
if (NS_SUCCEEDED(rv))
|
||||
PR_Notify(mRequestMonitor);
|
||||
}
|
||||
PR_ExitMonitor(mRequestMonitor);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsIRunnable*
|
||||
nsThreadPool::GetRequest()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsIRunnable* request = nsnull;
|
||||
|
||||
PR_EnterMonitor(mRequestMonitor);
|
||||
|
||||
while (mRequests->Count() == 0) {
|
||||
if (mShuttingDown) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
break;
|
||||
}
|
||||
// printf("thread %x waiting\n", PR_CurrentThread());
|
||||
PRStatus status = PR_Wait(mRequestMonitor, PR_INTERVAL_NO_TIMEOUT);
|
||||
if (status != PR_SUCCESS || mShuttingDown) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
NS_ASSERTION(mRequests->Count() > 0, "request queue out of sync");
|
||||
request = (nsIRunnable*)(*mRequests)[0];
|
||||
NS_ASSERTION(request != nsnull, "null runnable");
|
||||
|
||||
PRBool removed = mRequests->RemoveElementAt(0);
|
||||
NS_ASSERTION(removed, "nsISupportsArray broken");
|
||||
}
|
||||
PR_ExitMonitor(mRequestMonitor);
|
||||
return request;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsThreadPool::ProcessPendingRequests()
|
||||
{
|
||||
nsresult rv;
|
||||
PR_CEnterMonitor(this);
|
||||
|
||||
while (mRequests->Count() > 0) {
|
||||
PRStatus status = PR_CWait(this, PR_INTERVAL_NO_TIMEOUT);
|
||||
if (status != PR_SUCCESS) {
|
||||
rv = NS_ERROR_FAILURE; // our thread was interrupted!
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PR_CExitMonitor(this);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsThreadPool::Shutdown()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
PRUint32 count;
|
||||
PRUint32 i;
|
||||
|
||||
mShuttingDown = PR_TRUE;
|
||||
ProcessPendingRequests();
|
||||
|
||||
// then interrupt the threads and join them
|
||||
count = mThreads->Count();
|
||||
for (i = 0; i < count; i++) {
|
||||
nsIThread* thread = (nsIThread*)((*mThreads)[0]);
|
||||
|
||||
// we don't care about the error from Interrupt, because the
|
||||
// thread may have already terminated its event loop
|
||||
(void)thread->Interrupt();
|
||||
|
||||
rv = thread->Join();
|
||||
// don't break out of the loop because of an error here
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Join failed");
|
||||
|
||||
NS_RELEASE(thread);
|
||||
rv = mThreads->RemoveElementAt(0);
|
||||
// don't break out of the loop because of an error here
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "RemoveElementAt failed");
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_BASE nsresult
|
||||
NS_NewThreadPool(nsIThreadPool* *result,
|
||||
PRUint32 minThreads, PRUint32 maxThreads,
|
||||
PRUint32 stackSize,
|
||||
PRThreadPriority priority,
|
||||
PRThreadScope scope)
|
||||
{
|
||||
nsresult rv;
|
||||
nsThreadPool* pool = new nsThreadPool(minThreads, maxThreads);
|
||||
if (pool == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
rv = pool->Init(stackSize, priority, scope);
|
||||
if (NS_FAILED(rv)) {
|
||||
delete pool;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_ADDREF(pool);
|
||||
*result = pool;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsThreadPoolRunnable::nsThreadPoolRunnable(nsThreadPool* pool)
|
||||
: mPool(pool)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF(mPool);
|
||||
}
|
||||
|
||||
nsThreadPoolRunnable::~nsThreadPoolRunnable()
|
||||
{
|
||||
NS_RELEASE(mPool);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsThreadPoolRunnable, nsIRunnable::GetIID());
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsThreadPoolRunnable::Run()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsIRunnable* request;
|
||||
|
||||
// let the thread pool know we're ready
|
||||
PR_CEnterMonitor(mPool);
|
||||
PR_CNotify(mPool);
|
||||
PR_CExitMonitor(mPool);
|
||||
|
||||
while ((request = mPool->GetRequest()) != nsnull) {
|
||||
// printf("running %x, thread %x\n", this, PR_CurrentThread());
|
||||
rv = request->Run();
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "runnable failed");
|
||||
|
||||
// let the thread pool know we're finished a run
|
||||
PR_CEnterMonitor(mPool);
|
||||
PR_CNotify(mPool);
|
||||
PR_CExitMonitor(mPool);
|
||||
}
|
||||
// printf("quitting %x, thread %x\n", this, PR_CurrentThread());
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
|
@ -1488,7 +1488,10 @@ nsISupportsArray* StyleContextImpl::GetStyleRules(void) const
|
|||
PRInt32 StyleContextImpl::GetStyleRuleCount(void) const
|
||||
{
|
||||
if (nsnull != mRules) {
|
||||
return mRules->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mRules->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return 0; // XXX error?
|
||||
return cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1510,8 +1513,15 @@ StyleContextImpl::FindChildWithRules(const nsIAtom* aPseudoTag,
|
|||
|
||||
if ((nsnull != mChild) || (nsnull != mEmptyChild)) {
|
||||
StyleContextImpl* child;
|
||||
// cast away const-ness
|
||||
PRInt32 ruleCount = ((nsnull != aRules) ? ((nsISupportsArray*)aRules)->Count() : 0);
|
||||
PRInt32 ruleCount;
|
||||
if (aRules) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = ((nsISupportsArray*)aRules)->Count(&cnt); // XXX bogus cast -- aRules should not be const
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
ruleCount = cnt;
|
||||
}
|
||||
else
|
||||
ruleCount = 0;
|
||||
if (0 == ruleCount) {
|
||||
if (nsnull != mEmptyChild) {
|
||||
child = mEmptyChild;
|
||||
|
@ -1530,11 +1540,13 @@ StyleContextImpl::FindChildWithRules(const nsIAtom* aPseudoTag,
|
|||
aRules->EnumerateForwards(HashStyleRule, &hash);
|
||||
child = mChild;
|
||||
do {
|
||||
PRUint32 cnt;
|
||||
if ((0 == child->mDataCode) && // only look at children with un-twiddled data
|
||||
(child->mRuleHash == hash) &&
|
||||
(child->mPseudoTag == aPseudoTag) &&
|
||||
(nsnull != child->mRules) &&
|
||||
((PRInt32)child->mRules->Count() == ruleCount)) {
|
||||
NS_SUCCEEDED(child->mRules->Count(&cnt)) &&
|
||||
(PRInt32)cnt == ruleCount) {
|
||||
if (child->mRules->Equals(aRules)) {
|
||||
aResult = child;
|
||||
break;
|
||||
|
@ -1783,7 +1795,12 @@ StyleContextImpl::RemapStyle(nsIPresContext* aPresContext)
|
|||
mDisplay.ResetFrom(nsnull, aPresContext);
|
||||
}
|
||||
|
||||
if ((nsnull != mRules) && (0 < mRules->Count())) {
|
||||
PRUint32 cnt = 0;
|
||||
if (mRules) {
|
||||
nsresult rv = mRules->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
}
|
||||
if (0 < cnt) {
|
||||
MapStyleData data(this, aPresContext);
|
||||
mRules->EnumerateForwards(MapStyleRuleFont, &data);
|
||||
mRules->EnumerateForwards(MapStyleRule, &data);
|
||||
|
@ -1814,7 +1831,12 @@ StyleContextImpl::RemapStyle(nsIPresContext* aPresContext)
|
|||
mPosition.ResetFrom(nsnull, aPresContext);
|
||||
mDisplay.ResetFrom(nsnull, aPresContext);
|
||||
|
||||
if ((nsnull != mRules) && (0 < mRules->Count())) {
|
||||
PRUint32 cnt = 0;
|
||||
if (mRules) {
|
||||
nsresult rv = mRules->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
}
|
||||
if (0 < cnt) {
|
||||
MapStyleData data(this, aPresContext);
|
||||
mRules->EnumerateForwards(MapStyleRuleFont, &data);
|
||||
mRules->EnumerateForwards(MapStyleRule, &data);
|
||||
|
|
|
@ -259,7 +259,10 @@ void StyleSetImpl::RemoveOverrideStyleSheet(nsIStyleSheet* aSheet)
|
|||
PRInt32 StyleSetImpl::GetNumberOfOverrideStyleSheets()
|
||||
{
|
||||
if (nsnull != mOverrideSheets) {
|
||||
return mOverrideSheets->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mOverrideSheets->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return 0; // XXX error?
|
||||
return cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -282,7 +285,9 @@ void StyleSetImpl::AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocumen
|
|||
mDocSheets->RemoveElement(aSheet);
|
||||
// lowest index last
|
||||
PRInt32 newDocIndex = aDocument->GetIndexOfStyleSheet(aSheet);
|
||||
PRUint32 count = mDocSheets->Count();
|
||||
PRUint32 count;
|
||||
nsresult rv = mDocSheets->Count(&count);
|
||||
if (NS_FAILED(rv)) return; // XXX error?
|
||||
PRUint32 index;
|
||||
for (index = 0; index < count; index++) {
|
||||
nsIStyleSheet* sheet = (nsIStyleSheet*)mDocSheets->ElementAt(index);
|
||||
|
@ -293,7 +298,10 @@ void StyleSetImpl::AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocumen
|
|||
}
|
||||
NS_RELEASE(sheet);
|
||||
}
|
||||
if (mDocSheets->Count() == count) { // didn't insert it
|
||||
PRUint32 cnt;
|
||||
rv = mDocSheets->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return; // XXX error?
|
||||
if (cnt == count) { // didn't insert it
|
||||
mDocSheets->AppendElement(aSheet);
|
||||
}
|
||||
|
||||
|
@ -315,7 +323,10 @@ void StyleSetImpl::RemoveDocStyleSheet(nsIStyleSheet* aSheet)
|
|||
PRInt32 StyleSetImpl::GetNumberOfDocStyleSheets()
|
||||
{
|
||||
if (nsnull != mDocSheets) {
|
||||
return mDocSheets->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mDocSheets->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return 0; // XXX error?
|
||||
return cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -374,7 +385,10 @@ void StyleSetImpl::RemoveBackstopStyleSheet(nsIStyleSheet* aSheet)
|
|||
PRInt32 StyleSetImpl::GetNumberOfBackstopStyleSheets()
|
||||
{
|
||||
if (nsnull != mBackstopSheets) {
|
||||
return mBackstopSheets->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mBackstopSheets->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return 0; // XXX error?
|
||||
return cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -398,7 +412,10 @@ PRInt32 StyleSetImpl::RulesMatching(nsISupportsArray* aSheets,
|
|||
PRInt32 ruleCount = 0;
|
||||
|
||||
if (nsnull != aSheets) {
|
||||
PRInt32 index = aSheets->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = aSheets->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
PRInt32 index = (PRInt32)cnt;
|
||||
while (0 < index--) {
|
||||
nsIStyleSheet* sheet = (nsIStyleSheet*)aSheets->ElementAt(index);
|
||||
PRBool mediumOK = PR_FALSE;
|
||||
|
@ -472,7 +489,10 @@ nsIStyleContext* StyleSetImpl::GetContext(nsIPresContext* aPresContext,
|
|||
// XXX for now only works for strength 0 & 1
|
||||
static void SortRulesByStrength(nsISupportsArray* aRules, PRInt32& aBackstopRuleCount)
|
||||
{
|
||||
PRInt32 count = aRules->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = aRules->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return; // XXX error?
|
||||
PRInt32 count = (PRInt32)cnt;
|
||||
|
||||
if (1 < count) {
|
||||
PRInt32 index;
|
||||
|
@ -583,7 +603,10 @@ PRInt32 StyleSetImpl::RulesMatching(nsISupportsArray* aSheets,
|
|||
PRInt32 ruleCount = 0;
|
||||
|
||||
if (nsnull != aSheets) {
|
||||
PRInt32 index = aSheets->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = aSheets->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
PRInt32 index = (PRInt32)cnt;
|
||||
while (0 < index--) {
|
||||
nsIStyleSheet* sheet = (nsIStyleSheet*)aSheets->ElementAt(index);
|
||||
PRBool mediumOK = PR_FALSE;
|
||||
|
@ -887,9 +910,13 @@ StyleSetImpl::CreateContinuingFrame(nsIPresContext* aPresContext,
|
|||
|
||||
void StyleSetImpl::List(FILE* out, PRInt32 aIndent, nsISupportsArray* aSheets)
|
||||
{
|
||||
PRInt32 count = ((nsnull != aSheets) ? aSheets->Count() : 0);
|
||||
PRUint32 cnt = 0;
|
||||
if (aSheets) {
|
||||
nsresult rv = aSheets->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return; // XXX error?
|
||||
}
|
||||
|
||||
for (PRInt32 index = 0; index < count; index++) {
|
||||
for (PRInt32 index = 0; index < (PRInt32)cnt; index++) {
|
||||
nsIStyleSheet* sheet = (nsIStyleSheet*)aSheets->ElementAt(index);
|
||||
sheet->List(out, aIndent);
|
||||
fputs("\n", out);
|
||||
|
|
|
@ -1619,7 +1619,14 @@ CSSStyleSheetImpl::GetType(nsString& aType) const
|
|||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetMediumCount(PRInt32& aCount) const
|
||||
{
|
||||
aCount = ((nsnull != mMedia) ? mMedia->Count() : 0);
|
||||
if (mMedia) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mMedia->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
aCount = cnt;
|
||||
}
|
||||
else
|
||||
aCount = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1757,7 +1764,10 @@ void CSSStyleSheetImpl::PrependStyleRule(nsICSSStyleRule* aRule)
|
|||
if (NS_OK != NS_NewISupportsArray(mOrderedRules.AssignPtr()))
|
||||
return;
|
||||
}
|
||||
PRInt32 index = mWeightedRules->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mWeightedRules->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return; // XXX error?
|
||||
PRInt32 index = cnt;
|
||||
while (0 <= --index) {
|
||||
nsICSSStyleRule* rule = (nsICSSStyleRule*)mWeightedRules->ElementAt(index);
|
||||
if (rule->GetWeight() >= weight) { // insert before rules with equal or lesser weight
|
||||
|
@ -1786,7 +1796,10 @@ void CSSStyleSheetImpl::AppendStyleRule(nsICSSStyleRule* aRule)
|
|||
if (NS_OK != NS_NewISupportsArray(mOrderedRules.AssignPtr()))
|
||||
return;
|
||||
}
|
||||
PRInt32 count = mWeightedRules->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mWeightedRules->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return; // XXX error?
|
||||
PRInt32 count = cnt;
|
||||
PRInt32 index = -1;
|
||||
while (++index < count) {
|
||||
nsICSSStyleRule* rule = (nsICSSStyleRule*)mWeightedRules->ElementAt(index);
|
||||
|
@ -1804,8 +1817,10 @@ void CSSStyleSheetImpl::AppendStyleRule(nsICSSStyleRule* aRule)
|
|||
PRInt32 CSSStyleSheetImpl::StyleRuleCount(void) const
|
||||
{
|
||||
if (mOrderedRules.IsNotNull()) {
|
||||
// cast away const-ness
|
||||
return ((nsISupportsArrayPtr)mOrderedRules)->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = ((CSSStyleSheetImpl*)this)->mOrderedRules->Count(&cnt); // XXX bogus cast -- this method should not be const
|
||||
if (NS_FAILED(rv)) return 0; // XXX error?
|
||||
return cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1884,8 +1899,13 @@ void CSSStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
|
|||
child = ((CSSStyleSheetImpl*)child)->mNext;
|
||||
}
|
||||
|
||||
// cast away const-ness
|
||||
PRInt32 count = (mWeightedRules.IsNotNull() ? ((nsISupportsArrayPtr)mWeightedRules)->Count() : 0);
|
||||
PRInt32 count = 0;
|
||||
if (mWeightedRules.IsNotNull()) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = ((CSSStyleSheetImpl*)this)->mWeightedRules->Count(&cnt); // XXX bogus cast -- this method should not be const
|
||||
if (NS_FAILED(rv)) return; // XXX error?
|
||||
count = cnt;
|
||||
}
|
||||
|
||||
for (index = 0; index < count; index++) {
|
||||
nsICSSStyleRulePtr rule = (nsICSSStyleRule*)mWeightedRules->ElementAt(index);
|
||||
|
@ -2046,7 +2066,10 @@ CSSStyleSheetImpl::GetMedia(nsString& aMedia)
|
|||
{
|
||||
aMedia.Truncate();
|
||||
if (nsnull != mMedia) {
|
||||
PRInt32 count = mMedia->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mMedia->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
PRInt32 count = cnt;
|
||||
PRInt32 index = 0;
|
||||
nsAutoString buffer;
|
||||
while (index < count) {
|
||||
|
@ -2098,13 +2121,17 @@ CSSStyleSheetImpl::InsertRule(const nsString& aRule,
|
|||
NS_ASSERTION(tmp == this, "parser incorrectly created a new stylesheet");
|
||||
NS_RELEASE(tmp);
|
||||
NS_RELEASE(input);
|
||||
*aReturn = mOrderedRules->Count();
|
||||
if (nsnull != mDocument) {
|
||||
nsICSSStyleRule* rule;
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mOrderedRules->Count(&cnt);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
*aReturn = cnt;
|
||||
if (nsnull != mDocument) {
|
||||
nsICSSStyleRule* rule;
|
||||
|
||||
rule = (nsICSSStyleRule*)mOrderedRules->ElementAt(aIndex);
|
||||
mDocument->StyleRuleAdded(this, rule);
|
||||
NS_IF_RELEASE(rule);
|
||||
rule = (nsICSSStyleRule*)mOrderedRules->ElementAt(aIndex);
|
||||
mDocument->StyleRuleAdded(this, rule);
|
||||
NS_IF_RELEASE(rule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -460,7 +460,9 @@ PRInt32 HTMLCSSStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
|
|||
nsISupportsArray* aResults)
|
||||
{
|
||||
if (aPseudoTag == nsHTMLAtoms::firstLinePseudo) {
|
||||
if (aResults->Count()) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = aResults->Count(&cnt);
|
||||
if (NS_SUCCEEDED(rv) && cnt) {
|
||||
if (nsnull == mFirstLineRule) {
|
||||
mFirstLineRule = new CSSFirstLineRule(this);
|
||||
if (mFirstLineRule) {
|
||||
|
@ -474,7 +476,9 @@ PRInt32 HTMLCSSStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
|
|||
}
|
||||
}
|
||||
if (aPseudoTag == nsHTMLAtoms::firstLetterPseudo) {
|
||||
if (aResults->Count()) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = aResults->Count(&cnt);
|
||||
if (NS_SUCCEEDED(rv) && cnt) {
|
||||
if (nsnull == mFirstLetterRule) {
|
||||
mFirstLetterRule = new CSSFirstLetterRule(this);
|
||||
if (mFirstLetterRule) {
|
||||
|
|
|
@ -219,7 +219,10 @@ nsRDFDOMNodeList::GetLength(PRUint32* aLength)
|
|||
if (! aLength)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aLength = mElements->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mElements->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
*aLength = cnt;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -231,8 +234,11 @@ nsRDFDOMNodeList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
|
|||
if (! aReturn)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(aIndex < (PRUint32) mElements->Count(), "invalid arg");
|
||||
if (aIndex >= (PRUint32) mElements->Count())
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mElements->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
NS_PRECONDITION(aIndex < cnt, "invalid arg");
|
||||
if (aIndex >= (PRUint32) cnt)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
// Cast is okay because we're in a closed system.
|
||||
|
|
|
@ -1394,7 +1394,10 @@ RDFElementImpl::SetDocument(nsIDocument* aDocument, PRBool aDeep)
|
|||
}
|
||||
|
||||
if (aDeep && mChildren) {
|
||||
for (PRInt32 i = mChildren->Count() - 1; i >= 0; --i) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mChildren->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRInt32 i = cnt - 1; i >= 0; --i) {
|
||||
// XXX this entire block could be more rigorous about
|
||||
// dealing with failure.
|
||||
nsISupports* obj = mChildren->ElementAt(i);
|
||||
|
@ -1445,7 +1448,14 @@ RDFElementImpl::ChildCount(PRInt32& aResult) const
|
|||
if (NS_FAILED(rv = EnsureContentsGenerated()))
|
||||
return rv;
|
||||
|
||||
aResult = mChildren ? mChildren->Count() : 0;
|
||||
if (mChildren) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mChildren->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
aResult = cnt;
|
||||
}
|
||||
else
|
||||
aResult = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1574,7 +1584,10 @@ RDFElementImpl::AppendChildTo(nsIContent* aKid, PRBool aNotify)
|
|||
if (nsnull != doc) {
|
||||
aKid->SetDocument(doc, PR_TRUE);
|
||||
if (aNotify) {
|
||||
doc->ContentInserted(NS_STATIC_CAST(nsIStyledContent*, this), aKid, mChildren->Count() - 1);
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mChildren->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
doc->ContentInserted(NS_STATIC_CAST(nsIStyledContent*, this), aKid, cnt - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -839,12 +839,15 @@ XULDocumentImpl::~XULDocumentImpl()
|
|||
// to break ownership cycle
|
||||
if (mBuilders)
|
||||
{
|
||||
PRUint32 cnt = 0;
|
||||
nsresult rv = mBuilders->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("# of builders: %lu\n", (unsigned long)mBuilders->Count());
|
||||
printf("# of builders: %lu\n", (unsigned long)cnt);
|
||||
#endif
|
||||
|
||||
for (PRUint32 i = 0; i < mBuilders->Count(); ++i)
|
||||
for (PRUint32 i = 0; i < cnt; ++i)
|
||||
{
|
||||
// XXX we should QueryInterface() here
|
||||
nsIRDFContentModelBuilder* builder
|
||||
|
@ -2311,7 +2314,10 @@ XULDocumentImpl::CreateContents(nsIContent* aElement)
|
|||
if (! mBuilders)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
||||
PRUint32 cnt = 0;
|
||||
nsresult rv = mBuilders->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
for (PRUint32 i = 0; i < cnt; ++i) {
|
||||
// XXX we should QueryInterface() here
|
||||
nsIRDFContentModelBuilder* builder
|
||||
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
||||
|
@ -2710,8 +2716,11 @@ XULDocumentImpl::GetElementById(const nsString& aId, nsIDOMElement** aReturn)
|
|||
return rv;
|
||||
}
|
||||
|
||||
if (elements->Count() > 0) {
|
||||
if (elements->Count() > 1) {
|
||||
PRUint32 cnt = 0;
|
||||
rv = elements->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
if (cnt > 0) {
|
||||
if (cnt > 1) {
|
||||
// This is a scary case that our API doesn't deal with well.
|
||||
NS_WARNING("more than one element found with specified ID; returning first");
|
||||
}
|
||||
|
@ -3197,7 +3206,10 @@ XULDocumentImpl::GetInlineStyleSheet(nsIHTMLCSSStyleSheet** aResult)
|
|||
NS_IMETHODIMP
|
||||
XULDocumentImpl::OnSetNodeValue(nsIDOMNode* aNode, const nsString& aValue)
|
||||
{
|
||||
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mBuilders->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt; ++i) {
|
||||
nsIRDFContentModelBuilder* builder
|
||||
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
||||
|
||||
|
@ -3217,7 +3229,10 @@ XULDocumentImpl::OnSetNodeValue(nsIDOMNode* aNode, const nsString& aValue)
|
|||
NS_IMETHODIMP
|
||||
XULDocumentImpl::OnInsertBefore(nsIDOMNode* aParent, nsIDOMNode* aNewChild, nsIDOMNode* aRefChild)
|
||||
{
|
||||
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mBuilders->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt; ++i) {
|
||||
nsIRDFContentModelBuilder* builder
|
||||
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
||||
|
||||
|
@ -3237,7 +3252,10 @@ XULDocumentImpl::OnInsertBefore(nsIDOMNode* aParent, nsIDOMNode* aNewChild, nsID
|
|||
NS_IMETHODIMP
|
||||
XULDocumentImpl::OnReplaceChild(nsIDOMNode* aParent, nsIDOMNode* aNewChild, nsIDOMNode* aOldChild)
|
||||
{
|
||||
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mBuilders->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt; ++i) {
|
||||
nsIRDFContentModelBuilder* builder
|
||||
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
||||
|
||||
|
@ -3257,7 +3275,10 @@ XULDocumentImpl::OnReplaceChild(nsIDOMNode* aParent, nsIDOMNode* aNewChild, nsID
|
|||
NS_IMETHODIMP
|
||||
XULDocumentImpl::OnRemoveChild(nsIDOMNode* aParent, nsIDOMNode* aOldChild)
|
||||
{
|
||||
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mBuilders->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt; ++i) {
|
||||
nsIRDFContentModelBuilder* builder
|
||||
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
||||
|
||||
|
@ -3277,7 +3298,10 @@ XULDocumentImpl::OnRemoveChild(nsIDOMNode* aParent, nsIDOMNode* aOldChild)
|
|||
NS_IMETHODIMP
|
||||
XULDocumentImpl::OnAppendChild(nsIDOMNode* aParent, nsIDOMNode* aNewChild)
|
||||
{
|
||||
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mBuilders->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt; ++i) {
|
||||
nsIRDFContentModelBuilder* builder
|
||||
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
||||
|
||||
|
@ -3300,7 +3324,10 @@ XULDocumentImpl::OnAppendChild(nsIDOMNode* aParent, nsIDOMNode* aNewChild)
|
|||
NS_IMETHODIMP
|
||||
XULDocumentImpl::OnSetAttribute(nsIDOMElement* aElement, const nsString& aName, const nsString& aValue)
|
||||
{
|
||||
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mBuilders->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt; ++i) {
|
||||
nsIRDFContentModelBuilder* builder
|
||||
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
||||
|
||||
|
@ -3318,7 +3345,10 @@ XULDocumentImpl::OnSetAttribute(nsIDOMElement* aElement, const nsString& aName,
|
|||
NS_IMETHODIMP
|
||||
XULDocumentImpl::OnRemoveAttribute(nsIDOMElement* aElement, const nsString& aName)
|
||||
{
|
||||
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mBuilders->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt; ++i) {
|
||||
nsIRDFContentModelBuilder* builder
|
||||
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
||||
|
||||
|
@ -3336,7 +3366,10 @@ XULDocumentImpl::OnRemoveAttribute(nsIDOMElement* aElement, const nsString& aNam
|
|||
NS_IMETHODIMP
|
||||
XULDocumentImpl::OnSetAttributeNode(nsIDOMElement* aElement, nsIDOMAttr* aNewAttr)
|
||||
{
|
||||
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mBuilders->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt; ++i) {
|
||||
nsIRDFContentModelBuilder* builder
|
||||
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
||||
|
||||
|
@ -3354,7 +3387,10 @@ XULDocumentImpl::OnSetAttributeNode(nsIDOMElement* aElement, nsIDOMAttr* aNewAtt
|
|||
NS_IMETHODIMP
|
||||
XULDocumentImpl::OnRemoveAttributeNode(nsIDOMElement* aElement, nsIDOMAttr* aOldAttr)
|
||||
{
|
||||
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mBuilders->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt; ++i) {
|
||||
nsIRDFContentModelBuilder* builder
|
||||
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
||||
|
||||
|
|
|
@ -855,7 +855,10 @@ XULSortServiceImpl::SortTreeChildren(nsIContent *container, PRInt32 colIndex, so
|
|||
}
|
||||
}
|
||||
}
|
||||
unsigned long numElements = childArray->Count();
|
||||
PRUint32 cnt = 0;
|
||||
rv = childArray->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
unsigned long numElements = cnt;
|
||||
if (numElements > 0)
|
||||
{
|
||||
nsIContent ** flatArray = new nsIContent*[numElements];
|
||||
|
@ -943,10 +946,12 @@ XULSortServiceImpl::SortTreeChildren(nsIContent *container, PRInt32 colIndex, so
|
|||
flatArray = nsnull;
|
||||
}
|
||||
}
|
||||
for (int i = childArray->Count() - 1; i >= 0; i--)
|
||||
{
|
||||
childArray->RemoveElementAt(i);
|
||||
}
|
||||
rv = childArray->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (int i = cnt - 1; i >= 0; i--)
|
||||
{
|
||||
childArray->RemoveElementAt(i);
|
||||
}
|
||||
return(NS_OK);
|
||||
}
|
||||
|
||||
|
|
|
@ -553,16 +553,19 @@ RDFGenericBuilderImpl::CreateContents(nsIContent* aElement)
|
|||
}
|
||||
}
|
||||
|
||||
unsigned long numElements = tempArray->Count();
|
||||
if (numElements > 0)
|
||||
PRUint32 cnt = 0;
|
||||
rv = tempArray->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
unsigned long numElements = cnt;
|
||||
if (numElements > 0)
|
||||
{
|
||||
nsIRDFResource ** flatArray = new nsIRDFResource *[numElements];
|
||||
if (flatArray)
|
||||
{
|
||||
nsIRDFResource ** flatArray = new nsIRDFResource *[numElements];
|
||||
if (flatArray)
|
||||
{
|
||||
// flatten array of resources, sort them, then add as item elements
|
||||
unsigned long loop;
|
||||
|
||||
for (loop=0; loop<numElements; loop++)
|
||||
for (loop=0; loop<numElements; loop++)
|
||||
flatArray[loop] = (nsIRDFResource *)tempArray->ElementAt(loop);
|
||||
|
||||
if (nsnull != XULSortService)
|
||||
|
@ -570,26 +573,26 @@ RDFGenericBuilderImpl::CreateContents(nsIContent* aElement)
|
|||
XULSortService->OpenContainer(mDB, aElement, flatArray, numElements/2, 2*sizeof(nsIRDFResource *));
|
||||
}
|
||||
|
||||
for (loop=0; loop<numElements; loop+=2)
|
||||
{
|
||||
for (loop=0; loop<numElements; loop+=2)
|
||||
{
|
||||
if (NS_FAILED(rv = CreateWidgetItem(aElement, flatArray[loop+1], flatArray[loop], loop+1)))
|
||||
{
|
||||
NS_ERROR("unable to create widget item");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = numElements - 1; i >=0; i--)
|
||||
{
|
||||
for (int i = numElements - 1; i >=0; i--)
|
||||
{
|
||||
NS_IF_RELEASE(flatArray[i]);
|
||||
}
|
||||
}
|
||||
delete [] flatArray;
|
||||
}
|
||||
}
|
||||
for (int i = numElements - 1; i >= 0; i--)
|
||||
{
|
||||
tempArray->RemoveElementAt(i);
|
||||
}
|
||||
NS_IF_RELEASE(tempArray);
|
||||
}
|
||||
for (int i = numElements - 1; i >= 0; i--)
|
||||
{
|
||||
tempArray->RemoveElementAt(i);
|
||||
}
|
||||
NS_IF_RELEASE(tempArray);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -1053,7 +1056,10 @@ RDFGenericBuilderImpl::OnAssert(nsIRDFResource* aSubject,
|
|||
return rv;
|
||||
}
|
||||
|
||||
for (PRInt32 i = elements->Count() - 1; i >= 0; --i) {
|
||||
PRUint32 cnt = 0;
|
||||
rv = elements->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
for (PRInt32 i = cnt - 1; i >= 0; --i) {
|
||||
nsCOMPtr<nsIContent> element( do_QueryInterface(elements->ElementAt(i)) );
|
||||
|
||||
// XXX somehow figure out if building XUL kids on this
|
||||
|
@ -1137,7 +1143,10 @@ RDFGenericBuilderImpl::OnUnassert(nsIRDFResource* aSubject,
|
|||
return rv;
|
||||
}
|
||||
|
||||
for (PRInt32 i = elements->Count() - 1; i >= 0; --i) {
|
||||
PRUint32 cnt = 0;
|
||||
rv = elements->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
for (PRInt32 i = cnt - 1; i >= 0; --i) {
|
||||
nsCOMPtr<nsIContent> element( do_QueryInterface(elements->ElementAt(i)) );
|
||||
|
||||
// XXX somehow figure out if building XUL kids on this
|
||||
|
|
|
@ -254,7 +254,10 @@ NS_IMETHODIMP
|
|||
nsRangeListIterator::Next()
|
||||
{
|
||||
mIndex++;
|
||||
if (mIndex < (PRInt32)mRangeList->mRangeArray->Count())
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mRangeList->mRangeArray->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (mIndex < (PRInt32)cnt)
|
||||
return NS_OK;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -288,7 +291,10 @@ nsRangeListIterator::Last()
|
|||
{
|
||||
if (!mRangeList)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
mIndex = (PRInt32)mRangeList->mRangeArray->Count()-1;
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mRangeList->mRangeArray->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
mIndex = (PRInt32)cnt-1;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -299,7 +305,10 @@ nsRangeListIterator::CurrentItem(nsISupports **aItem)
|
|||
{
|
||||
if (!aItem)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (mIndex >=0 && mIndex < (PRInt32)mRangeList->mRangeArray->Count()){
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mRangeList->mRangeArray->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (mIndex >=0 && mIndex < (PRInt32)cnt){
|
||||
*aItem = mRangeList->mRangeArray->ElementAt(mIndex);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -313,7 +322,10 @@ nsRangeListIterator::CurrentItem(nsIDOMRange **aItem)
|
|||
{
|
||||
if (!aItem)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (mIndex >=0 && mIndex < (PRInt32)mRangeList->mRangeArray->Count()){
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mRangeList->mRangeArray->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (mIndex >=0 && mIndex < (PRInt32)cnt){
|
||||
nsCOMPtr<nsISupports> indexIsupports = dont_AddRef(mRangeList->mRangeArray->ElementAt(mIndex));
|
||||
return indexIsupports->QueryInterface(nsIDOMRange::GetIID(),(void **)aItem);
|
||||
}
|
||||
|
@ -325,7 +337,10 @@ nsRangeListIterator::CurrentItem(nsIDOMRange **aItem)
|
|||
NS_IMETHODIMP
|
||||
nsRangeListIterator::IsDone()
|
||||
{
|
||||
if (mIndex >= 0 && mIndex < (PRInt32)mRangeList->mRangeArray->Count() ) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mRangeList->mRangeArray->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (mIndex >= 0 && mIndex < (PRInt32)cnt ) {
|
||||
return NS_COMFALSE;
|
||||
}
|
||||
return NS_OK;
|
||||
|
@ -400,7 +415,10 @@ nsRangeList::~nsRangeList()
|
|||
{
|
||||
if (mRangeArray)
|
||||
{
|
||||
for (PRUint32 i=0;i < mRangeArray->Count(); i++)
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mRangeArray->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
for (PRUint32 i=0;i < cnt; i++)
|
||||
{
|
||||
mRangeArray->RemoveElementAt(i);
|
||||
}
|
||||
|
@ -408,7 +426,10 @@ nsRangeList::~nsRangeList()
|
|||
|
||||
if (mSelectionListeners)
|
||||
{
|
||||
for (PRUint32 i=0;i < mSelectionListeners->Count(); i++)
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mSelectionListeners->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
for (PRUint32 i=0;i < cnt; i++)
|
||||
{
|
||||
mSelectionListeners->RemoveElementAt(i);
|
||||
}
|
||||
|
@ -530,7 +551,10 @@ NS_METHOD nsRangeList::GetFocusOffset(PRInt32* aFocusOffset)
|
|||
|
||||
void nsRangeList::setAnchorFocusRange(PRInt32 index)
|
||||
{
|
||||
if (((PRUint32)index) >= mRangeArray->Count() )
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mRangeArray->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return; // XXX error?
|
||||
if (((PRUint32)index) >= cnt )
|
||||
return;
|
||||
if (index < 0) //release all
|
||||
{
|
||||
|
@ -608,7 +632,10 @@ nsRangeList::RemoveItem(nsISupports *aItem)
|
|||
return NS_ERROR_FAILURE;
|
||||
if (!aItem )
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
for (PRUint32 i = 0; i < mRangeArray->Count();i++)
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mRangeArray->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt;i++)
|
||||
{
|
||||
nsCOMPtr<nsISupports> indexIsupports = dont_AddRef(mRangeArray->ElementAt(i));
|
||||
|
||||
|
@ -630,8 +657,13 @@ nsRangeList::Clear()
|
|||
if (!mRangeArray)
|
||||
return NS_ERROR_FAILURE;
|
||||
// Get an iterator
|
||||
while ( mRangeArray->Count())
|
||||
while (PR_TRUE)
|
||||
{
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mRangeArray->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (cnt == 0)
|
||||
break;
|
||||
nsCOMPtr<nsIDOMRange> range;
|
||||
nsCOMPtr<nsISupports> isupportsindex = dont_AddRef(mRangeArray->ElementAt(0));
|
||||
range = do_QueryInterface(isupportsindex);
|
||||
|
@ -801,8 +833,10 @@ if (!aGuiEvent)
|
|||
#ifdef DEBUG
|
||||
void nsRangeList::printSelection()
|
||||
{
|
||||
PRUint32 cnt;
|
||||
(void)mRangeArray->Count(&cnt);
|
||||
printf("nsRangeList 0x%lx: %d items\n", (unsigned long)this,
|
||||
mRangeArray ? mRangeArray->Count() : -99);
|
||||
mRangeArray ? cnt : -99);
|
||||
|
||||
// Get an iterator
|
||||
nsRangeListIterator iter(this);
|
||||
|
@ -936,7 +970,10 @@ nsRangeList::LookUpSelection(nsIContent *aContent, PRInt32 aContentOffset, PRInt
|
|||
return NS_ERROR_FAILURE;
|
||||
|
||||
*aDrawSelected = PR_FALSE;
|
||||
for (PRUint32 i =0; i<mRangeArray->Count() && i < 1; i++){
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mRangeArray->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i =0; i<cnt && i < 1; i++){
|
||||
nsCOMPtr<nsIDOMRange> range;
|
||||
nsCOMPtr<nsISupports> isupportsindex = dont_AddRef(mRangeArray->ElementAt(i));
|
||||
range = do_QueryInterface(isupportsindex);
|
||||
|
@ -1083,7 +1120,10 @@ nsRangeList::NotifySelectionListeners()
|
|||
SetDirty();
|
||||
return NS_OK;
|
||||
}
|
||||
for (PRUint32 i = 0; i < mSelectionListeners->Count();i++)
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mSelectionListeners->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt;i++)
|
||||
{
|
||||
nsCOMPtr<nsIDOMSelectionListener> thisListener;
|
||||
nsCOMPtr<nsISupports> isupports(dont_AddRef(mSelectionListeners->ElementAt(i)));
|
||||
|
@ -1205,13 +1245,18 @@ nsRangeList::GetIsCollapsed(PRBool* aIsCollapsed)
|
|||
if (!aIsCollapsed)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (!mRangeArray || (mRangeArray->Count() == 0))
|
||||
PRUint32 cnt = 0;
|
||||
if (mRangeArray) {
|
||||
nsresult rv = mRangeArray->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
if (!mRangeArray || (cnt == 0))
|
||||
{
|
||||
*aIsCollapsed = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (mRangeArray->Count() != 1)
|
||||
if (cnt != 1)
|
||||
{
|
||||
*aIsCollapsed = PR_FALSE;
|
||||
return NS_OK;
|
||||
|
@ -1237,7 +1282,10 @@ nsRangeList::GetRangeCount(PRInt32* aRangeCount)
|
|||
|
||||
if (mRangeArray)
|
||||
{
|
||||
*aRangeCount = mRangeArray->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mRangeArray->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
*aRangeCount = cnt;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1256,7 +1304,10 @@ nsRangeList::GetRangeAt(PRInt32 aIndex, nsIDOMRange** aReturn)
|
|||
if (!mRangeArray)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
if (aIndex < 0 || ((PRUint32)aIndex) >= mRangeArray->Count())
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mRangeArray->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (aIndex < 0 || ((PRUint32)aIndex) >= cnt)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
// the result of all this is one additional ref on the item, as
|
||||
|
@ -1317,7 +1368,10 @@ nsRangeList::Extend(nsIDOMNode* aParentNode, PRInt32 aOffset)
|
|||
|
||||
PRUint32 i;
|
||||
PRBool found = PR_FALSE;
|
||||
for (i = 0; i < mRangeArray->Count(); i++)
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mRangeArray->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (i = 0; i < cnt; i++)
|
||||
{
|
||||
nsCOMPtr<nsISupports> isupportsindex = dont_AddRef(mRangeArray->ElementAt(i));
|
||||
nsCOMPtr<nsIDOMRange> range (do_QueryInterface(isupportsindex));
|
||||
|
|
|
@ -1488,7 +1488,10 @@ nsISupportsArray* StyleContextImpl::GetStyleRules(void) const
|
|||
PRInt32 StyleContextImpl::GetStyleRuleCount(void) const
|
||||
{
|
||||
if (nsnull != mRules) {
|
||||
return mRules->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mRules->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return 0; // XXX error?
|
||||
return cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1510,8 +1513,15 @@ StyleContextImpl::FindChildWithRules(const nsIAtom* aPseudoTag,
|
|||
|
||||
if ((nsnull != mChild) || (nsnull != mEmptyChild)) {
|
||||
StyleContextImpl* child;
|
||||
// cast away const-ness
|
||||
PRInt32 ruleCount = ((nsnull != aRules) ? ((nsISupportsArray*)aRules)->Count() : 0);
|
||||
PRInt32 ruleCount;
|
||||
if (aRules) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = ((nsISupportsArray*)aRules)->Count(&cnt); // XXX bogus cast -- aRules should not be const
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
ruleCount = cnt;
|
||||
}
|
||||
else
|
||||
ruleCount = 0;
|
||||
if (0 == ruleCount) {
|
||||
if (nsnull != mEmptyChild) {
|
||||
child = mEmptyChild;
|
||||
|
@ -1530,11 +1540,13 @@ StyleContextImpl::FindChildWithRules(const nsIAtom* aPseudoTag,
|
|||
aRules->EnumerateForwards(HashStyleRule, &hash);
|
||||
child = mChild;
|
||||
do {
|
||||
PRUint32 cnt;
|
||||
if ((0 == child->mDataCode) && // only look at children with un-twiddled data
|
||||
(child->mRuleHash == hash) &&
|
||||
(child->mPseudoTag == aPseudoTag) &&
|
||||
(nsnull != child->mRules) &&
|
||||
((PRInt32)child->mRules->Count() == ruleCount)) {
|
||||
NS_SUCCEEDED(child->mRules->Count(&cnt)) &&
|
||||
(PRInt32)cnt == ruleCount) {
|
||||
if (child->mRules->Equals(aRules)) {
|
||||
aResult = child;
|
||||
break;
|
||||
|
@ -1783,7 +1795,12 @@ StyleContextImpl::RemapStyle(nsIPresContext* aPresContext)
|
|||
mDisplay.ResetFrom(nsnull, aPresContext);
|
||||
}
|
||||
|
||||
if ((nsnull != mRules) && (0 < mRules->Count())) {
|
||||
PRUint32 cnt = 0;
|
||||
if (mRules) {
|
||||
nsresult rv = mRules->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
}
|
||||
if (0 < cnt) {
|
||||
MapStyleData data(this, aPresContext);
|
||||
mRules->EnumerateForwards(MapStyleRuleFont, &data);
|
||||
mRules->EnumerateForwards(MapStyleRule, &data);
|
||||
|
@ -1814,7 +1831,12 @@ StyleContextImpl::RemapStyle(nsIPresContext* aPresContext)
|
|||
mPosition.ResetFrom(nsnull, aPresContext);
|
||||
mDisplay.ResetFrom(nsnull, aPresContext);
|
||||
|
||||
if ((nsnull != mRules) && (0 < mRules->Count())) {
|
||||
PRUint32 cnt = 0;
|
||||
if (mRules) {
|
||||
nsresult rv = mRules->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
}
|
||||
if (0 < cnt) {
|
||||
MapStyleData data(this, aPresContext);
|
||||
mRules->EnumerateForwards(MapStyleRuleFont, &data);
|
||||
mRules->EnumerateForwards(MapStyleRule, &data);
|
||||
|
|
|
@ -259,7 +259,10 @@ void StyleSetImpl::RemoveOverrideStyleSheet(nsIStyleSheet* aSheet)
|
|||
PRInt32 StyleSetImpl::GetNumberOfOverrideStyleSheets()
|
||||
{
|
||||
if (nsnull != mOverrideSheets) {
|
||||
return mOverrideSheets->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mOverrideSheets->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return 0; // XXX error?
|
||||
return cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -282,7 +285,9 @@ void StyleSetImpl::AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocumen
|
|||
mDocSheets->RemoveElement(aSheet);
|
||||
// lowest index last
|
||||
PRInt32 newDocIndex = aDocument->GetIndexOfStyleSheet(aSheet);
|
||||
PRUint32 count = mDocSheets->Count();
|
||||
PRUint32 count;
|
||||
nsresult rv = mDocSheets->Count(&count);
|
||||
if (NS_FAILED(rv)) return; // XXX error?
|
||||
PRUint32 index;
|
||||
for (index = 0; index < count; index++) {
|
||||
nsIStyleSheet* sheet = (nsIStyleSheet*)mDocSheets->ElementAt(index);
|
||||
|
@ -293,7 +298,10 @@ void StyleSetImpl::AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocumen
|
|||
}
|
||||
NS_RELEASE(sheet);
|
||||
}
|
||||
if (mDocSheets->Count() == count) { // didn't insert it
|
||||
PRUint32 cnt;
|
||||
rv = mDocSheets->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return; // XXX error?
|
||||
if (cnt == count) { // didn't insert it
|
||||
mDocSheets->AppendElement(aSheet);
|
||||
}
|
||||
|
||||
|
@ -315,7 +323,10 @@ void StyleSetImpl::RemoveDocStyleSheet(nsIStyleSheet* aSheet)
|
|||
PRInt32 StyleSetImpl::GetNumberOfDocStyleSheets()
|
||||
{
|
||||
if (nsnull != mDocSheets) {
|
||||
return mDocSheets->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mDocSheets->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return 0; // XXX error?
|
||||
return cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -374,7 +385,10 @@ void StyleSetImpl::RemoveBackstopStyleSheet(nsIStyleSheet* aSheet)
|
|||
PRInt32 StyleSetImpl::GetNumberOfBackstopStyleSheets()
|
||||
{
|
||||
if (nsnull != mBackstopSheets) {
|
||||
return mBackstopSheets->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mBackstopSheets->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return 0; // XXX error?
|
||||
return cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -398,7 +412,10 @@ PRInt32 StyleSetImpl::RulesMatching(nsISupportsArray* aSheets,
|
|||
PRInt32 ruleCount = 0;
|
||||
|
||||
if (nsnull != aSheets) {
|
||||
PRInt32 index = aSheets->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = aSheets->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
PRInt32 index = (PRInt32)cnt;
|
||||
while (0 < index--) {
|
||||
nsIStyleSheet* sheet = (nsIStyleSheet*)aSheets->ElementAt(index);
|
||||
PRBool mediumOK = PR_FALSE;
|
||||
|
@ -472,7 +489,10 @@ nsIStyleContext* StyleSetImpl::GetContext(nsIPresContext* aPresContext,
|
|||
// XXX for now only works for strength 0 & 1
|
||||
static void SortRulesByStrength(nsISupportsArray* aRules, PRInt32& aBackstopRuleCount)
|
||||
{
|
||||
PRInt32 count = aRules->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = aRules->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return; // XXX error?
|
||||
PRInt32 count = (PRInt32)cnt;
|
||||
|
||||
if (1 < count) {
|
||||
PRInt32 index;
|
||||
|
@ -583,7 +603,10 @@ PRInt32 StyleSetImpl::RulesMatching(nsISupportsArray* aSheets,
|
|||
PRInt32 ruleCount = 0;
|
||||
|
||||
if (nsnull != aSheets) {
|
||||
PRInt32 index = aSheets->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = aSheets->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
PRInt32 index = (PRInt32)cnt;
|
||||
while (0 < index--) {
|
||||
nsIStyleSheet* sheet = (nsIStyleSheet*)aSheets->ElementAt(index);
|
||||
PRBool mediumOK = PR_FALSE;
|
||||
|
@ -887,9 +910,13 @@ StyleSetImpl::CreateContinuingFrame(nsIPresContext* aPresContext,
|
|||
|
||||
void StyleSetImpl::List(FILE* out, PRInt32 aIndent, nsISupportsArray* aSheets)
|
||||
{
|
||||
PRInt32 count = ((nsnull != aSheets) ? aSheets->Count() : 0);
|
||||
PRUint32 cnt = 0;
|
||||
if (aSheets) {
|
||||
nsresult rv = aSheets->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return; // XXX error?
|
||||
}
|
||||
|
||||
for (PRInt32 index = 0; index < count; index++) {
|
||||
for (PRInt32 index = 0; index < (PRInt32)cnt; index++) {
|
||||
nsIStyleSheet* sheet = (nsIStyleSheet*)aSheets->ElementAt(index);
|
||||
sheet->List(out, aIndent);
|
||||
fputs("\n", out);
|
||||
|
|
|
@ -1619,7 +1619,14 @@ CSSStyleSheetImpl::GetType(nsString& aType) const
|
|||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetMediumCount(PRInt32& aCount) const
|
||||
{
|
||||
aCount = ((nsnull != mMedia) ? mMedia->Count() : 0);
|
||||
if (mMedia) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mMedia->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
aCount = cnt;
|
||||
}
|
||||
else
|
||||
aCount = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1757,7 +1764,10 @@ void CSSStyleSheetImpl::PrependStyleRule(nsICSSStyleRule* aRule)
|
|||
if (NS_OK != NS_NewISupportsArray(mOrderedRules.AssignPtr()))
|
||||
return;
|
||||
}
|
||||
PRInt32 index = mWeightedRules->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mWeightedRules->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return; // XXX error?
|
||||
PRInt32 index = cnt;
|
||||
while (0 <= --index) {
|
||||
nsICSSStyleRule* rule = (nsICSSStyleRule*)mWeightedRules->ElementAt(index);
|
||||
if (rule->GetWeight() >= weight) { // insert before rules with equal or lesser weight
|
||||
|
@ -1786,7 +1796,10 @@ void CSSStyleSheetImpl::AppendStyleRule(nsICSSStyleRule* aRule)
|
|||
if (NS_OK != NS_NewISupportsArray(mOrderedRules.AssignPtr()))
|
||||
return;
|
||||
}
|
||||
PRInt32 count = mWeightedRules->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mWeightedRules->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return; // XXX error?
|
||||
PRInt32 count = cnt;
|
||||
PRInt32 index = -1;
|
||||
while (++index < count) {
|
||||
nsICSSStyleRule* rule = (nsICSSStyleRule*)mWeightedRules->ElementAt(index);
|
||||
|
@ -1804,8 +1817,10 @@ void CSSStyleSheetImpl::AppendStyleRule(nsICSSStyleRule* aRule)
|
|||
PRInt32 CSSStyleSheetImpl::StyleRuleCount(void) const
|
||||
{
|
||||
if (mOrderedRules.IsNotNull()) {
|
||||
// cast away const-ness
|
||||
return ((nsISupportsArrayPtr)mOrderedRules)->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = ((CSSStyleSheetImpl*)this)->mOrderedRules->Count(&cnt); // XXX bogus cast -- this method should not be const
|
||||
if (NS_FAILED(rv)) return 0; // XXX error?
|
||||
return cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1884,8 +1899,13 @@ void CSSStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
|
|||
child = ((CSSStyleSheetImpl*)child)->mNext;
|
||||
}
|
||||
|
||||
// cast away const-ness
|
||||
PRInt32 count = (mWeightedRules.IsNotNull() ? ((nsISupportsArrayPtr)mWeightedRules)->Count() : 0);
|
||||
PRInt32 count = 0;
|
||||
if (mWeightedRules.IsNotNull()) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = ((CSSStyleSheetImpl*)this)->mWeightedRules->Count(&cnt); // XXX bogus cast -- this method should not be const
|
||||
if (NS_FAILED(rv)) return; // XXX error?
|
||||
count = cnt;
|
||||
}
|
||||
|
||||
for (index = 0; index < count; index++) {
|
||||
nsICSSStyleRulePtr rule = (nsICSSStyleRule*)mWeightedRules->ElementAt(index);
|
||||
|
@ -2046,7 +2066,10 @@ CSSStyleSheetImpl::GetMedia(nsString& aMedia)
|
|||
{
|
||||
aMedia.Truncate();
|
||||
if (nsnull != mMedia) {
|
||||
PRInt32 count = mMedia->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mMedia->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
PRInt32 count = cnt;
|
||||
PRInt32 index = 0;
|
||||
nsAutoString buffer;
|
||||
while (index < count) {
|
||||
|
@ -2098,13 +2121,17 @@ CSSStyleSheetImpl::InsertRule(const nsString& aRule,
|
|||
NS_ASSERTION(tmp == this, "parser incorrectly created a new stylesheet");
|
||||
NS_RELEASE(tmp);
|
||||
NS_RELEASE(input);
|
||||
*aReturn = mOrderedRules->Count();
|
||||
if (nsnull != mDocument) {
|
||||
nsICSSStyleRule* rule;
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mOrderedRules->Count(&cnt);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
*aReturn = cnt;
|
||||
if (nsnull != mDocument) {
|
||||
nsICSSStyleRule* rule;
|
||||
|
||||
rule = (nsICSSStyleRule*)mOrderedRules->ElementAt(aIndex);
|
||||
mDocument->StyleRuleAdded(this, rule);
|
||||
NS_IF_RELEASE(rule);
|
||||
rule = (nsICSSStyleRule*)mOrderedRules->ElementAt(aIndex);
|
||||
mDocument->StyleRuleAdded(this, rule);
|
||||
NS_IF_RELEASE(rule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -460,7 +460,9 @@ PRInt32 HTMLCSSStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
|
|||
nsISupportsArray* aResults)
|
||||
{
|
||||
if (aPseudoTag == nsHTMLAtoms::firstLinePseudo) {
|
||||
if (aResults->Count()) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = aResults->Count(&cnt);
|
||||
if (NS_SUCCEEDED(rv) && cnt) {
|
||||
if (nsnull == mFirstLineRule) {
|
||||
mFirstLineRule = new CSSFirstLineRule(this);
|
||||
if (mFirstLineRule) {
|
||||
|
@ -474,7 +476,9 @@ PRInt32 HTMLCSSStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
|
|||
}
|
||||
}
|
||||
if (aPseudoTag == nsHTMLAtoms::firstLetterPseudo) {
|
||||
if (aResults->Count()) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = aResults->Count(&cnt);
|
||||
if (NS_SUCCEEDED(rv) && cnt) {
|
||||
if (nsnull == mFirstLetterRule) {
|
||||
mFirstLetterRule = new CSSFirstLetterRule(this);
|
||||
if (mFirstLetterRule) {
|
||||
|
|
|
@ -1619,7 +1619,14 @@ CSSStyleSheetImpl::GetType(nsString& aType) const
|
|||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetMediumCount(PRInt32& aCount) const
|
||||
{
|
||||
aCount = ((nsnull != mMedia) ? mMedia->Count() : 0);
|
||||
if (mMedia) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mMedia->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
aCount = cnt;
|
||||
}
|
||||
else
|
||||
aCount = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1757,7 +1764,10 @@ void CSSStyleSheetImpl::PrependStyleRule(nsICSSStyleRule* aRule)
|
|||
if (NS_OK != NS_NewISupportsArray(mOrderedRules.AssignPtr()))
|
||||
return;
|
||||
}
|
||||
PRInt32 index = mWeightedRules->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mWeightedRules->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return; // XXX error?
|
||||
PRInt32 index = cnt;
|
||||
while (0 <= --index) {
|
||||
nsICSSStyleRule* rule = (nsICSSStyleRule*)mWeightedRules->ElementAt(index);
|
||||
if (rule->GetWeight() >= weight) { // insert before rules with equal or lesser weight
|
||||
|
@ -1786,7 +1796,10 @@ void CSSStyleSheetImpl::AppendStyleRule(nsICSSStyleRule* aRule)
|
|||
if (NS_OK != NS_NewISupportsArray(mOrderedRules.AssignPtr()))
|
||||
return;
|
||||
}
|
||||
PRInt32 count = mWeightedRules->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mWeightedRules->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return; // XXX error?
|
||||
PRInt32 count = cnt;
|
||||
PRInt32 index = -1;
|
||||
while (++index < count) {
|
||||
nsICSSStyleRule* rule = (nsICSSStyleRule*)mWeightedRules->ElementAt(index);
|
||||
|
@ -1804,8 +1817,10 @@ void CSSStyleSheetImpl::AppendStyleRule(nsICSSStyleRule* aRule)
|
|||
PRInt32 CSSStyleSheetImpl::StyleRuleCount(void) const
|
||||
{
|
||||
if (mOrderedRules.IsNotNull()) {
|
||||
// cast away const-ness
|
||||
return ((nsISupportsArrayPtr)mOrderedRules)->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = ((CSSStyleSheetImpl*)this)->mOrderedRules->Count(&cnt); // XXX bogus cast -- this method should not be const
|
||||
if (NS_FAILED(rv)) return 0; // XXX error?
|
||||
return cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1884,8 +1899,13 @@ void CSSStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
|
|||
child = ((CSSStyleSheetImpl*)child)->mNext;
|
||||
}
|
||||
|
||||
// cast away const-ness
|
||||
PRInt32 count = (mWeightedRules.IsNotNull() ? ((nsISupportsArrayPtr)mWeightedRules)->Count() : 0);
|
||||
PRInt32 count = 0;
|
||||
if (mWeightedRules.IsNotNull()) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = ((CSSStyleSheetImpl*)this)->mWeightedRules->Count(&cnt); // XXX bogus cast -- this method should not be const
|
||||
if (NS_FAILED(rv)) return; // XXX error?
|
||||
count = cnt;
|
||||
}
|
||||
|
||||
for (index = 0; index < count; index++) {
|
||||
nsICSSStyleRulePtr rule = (nsICSSStyleRule*)mWeightedRules->ElementAt(index);
|
||||
|
@ -2046,7 +2066,10 @@ CSSStyleSheetImpl::GetMedia(nsString& aMedia)
|
|||
{
|
||||
aMedia.Truncate();
|
||||
if (nsnull != mMedia) {
|
||||
PRInt32 count = mMedia->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mMedia->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
PRInt32 count = cnt;
|
||||
PRInt32 index = 0;
|
||||
nsAutoString buffer;
|
||||
while (index < count) {
|
||||
|
@ -2098,13 +2121,17 @@ CSSStyleSheetImpl::InsertRule(const nsString& aRule,
|
|||
NS_ASSERTION(tmp == this, "parser incorrectly created a new stylesheet");
|
||||
NS_RELEASE(tmp);
|
||||
NS_RELEASE(input);
|
||||
*aReturn = mOrderedRules->Count();
|
||||
if (nsnull != mDocument) {
|
||||
nsICSSStyleRule* rule;
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mOrderedRules->Count(&cnt);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
*aReturn = cnt;
|
||||
if (nsnull != mDocument) {
|
||||
nsICSSStyleRule* rule;
|
||||
|
||||
rule = (nsICSSStyleRule*)mOrderedRules->ElementAt(aIndex);
|
||||
mDocument->StyleRuleAdded(this, rule);
|
||||
NS_IF_RELEASE(rule);
|
||||
rule = (nsICSSStyleRule*)mOrderedRules->ElementAt(aIndex);
|
||||
mDocument->StyleRuleAdded(this, rule);
|
||||
NS_IF_RELEASE(rule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -460,7 +460,9 @@ PRInt32 HTMLCSSStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
|
|||
nsISupportsArray* aResults)
|
||||
{
|
||||
if (aPseudoTag == nsHTMLAtoms::firstLinePseudo) {
|
||||
if (aResults->Count()) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = aResults->Count(&cnt);
|
||||
if (NS_SUCCEEDED(rv) && cnt) {
|
||||
if (nsnull == mFirstLineRule) {
|
||||
mFirstLineRule = new CSSFirstLineRule(this);
|
||||
if (mFirstLineRule) {
|
||||
|
@ -474,7 +476,9 @@ PRInt32 HTMLCSSStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
|
|||
}
|
||||
}
|
||||
if (aPseudoTag == nsHTMLAtoms::firstLetterPseudo) {
|
||||
if (aResults->Count()) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = aResults->Count(&cnt);
|
||||
if (NS_SUCCEEDED(rv) && cnt) {
|
||||
if (nsnull == mFirstLetterRule) {
|
||||
mFirstLetterRule = new CSSFirstLetterRule(this);
|
||||
if (mFirstLetterRule) {
|
||||
|
|
|
@ -1488,7 +1488,10 @@ nsISupportsArray* StyleContextImpl::GetStyleRules(void) const
|
|||
PRInt32 StyleContextImpl::GetStyleRuleCount(void) const
|
||||
{
|
||||
if (nsnull != mRules) {
|
||||
return mRules->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mRules->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return 0; // XXX error?
|
||||
return cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1510,8 +1513,15 @@ StyleContextImpl::FindChildWithRules(const nsIAtom* aPseudoTag,
|
|||
|
||||
if ((nsnull != mChild) || (nsnull != mEmptyChild)) {
|
||||
StyleContextImpl* child;
|
||||
// cast away const-ness
|
||||
PRInt32 ruleCount = ((nsnull != aRules) ? ((nsISupportsArray*)aRules)->Count() : 0);
|
||||
PRInt32 ruleCount;
|
||||
if (aRules) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = ((nsISupportsArray*)aRules)->Count(&cnt); // XXX bogus cast -- aRules should not be const
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
ruleCount = cnt;
|
||||
}
|
||||
else
|
||||
ruleCount = 0;
|
||||
if (0 == ruleCount) {
|
||||
if (nsnull != mEmptyChild) {
|
||||
child = mEmptyChild;
|
||||
|
@ -1530,11 +1540,13 @@ StyleContextImpl::FindChildWithRules(const nsIAtom* aPseudoTag,
|
|||
aRules->EnumerateForwards(HashStyleRule, &hash);
|
||||
child = mChild;
|
||||
do {
|
||||
PRUint32 cnt;
|
||||
if ((0 == child->mDataCode) && // only look at children with un-twiddled data
|
||||
(child->mRuleHash == hash) &&
|
||||
(child->mPseudoTag == aPseudoTag) &&
|
||||
(nsnull != child->mRules) &&
|
||||
((PRInt32)child->mRules->Count() == ruleCount)) {
|
||||
NS_SUCCEEDED(child->mRules->Count(&cnt)) &&
|
||||
(PRInt32)cnt == ruleCount) {
|
||||
if (child->mRules->Equals(aRules)) {
|
||||
aResult = child;
|
||||
break;
|
||||
|
@ -1783,7 +1795,12 @@ StyleContextImpl::RemapStyle(nsIPresContext* aPresContext)
|
|||
mDisplay.ResetFrom(nsnull, aPresContext);
|
||||
}
|
||||
|
||||
if ((nsnull != mRules) && (0 < mRules->Count())) {
|
||||
PRUint32 cnt = 0;
|
||||
if (mRules) {
|
||||
nsresult rv = mRules->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
}
|
||||
if (0 < cnt) {
|
||||
MapStyleData data(this, aPresContext);
|
||||
mRules->EnumerateForwards(MapStyleRuleFont, &data);
|
||||
mRules->EnumerateForwards(MapStyleRule, &data);
|
||||
|
@ -1814,7 +1831,12 @@ StyleContextImpl::RemapStyle(nsIPresContext* aPresContext)
|
|||
mPosition.ResetFrom(nsnull, aPresContext);
|
||||
mDisplay.ResetFrom(nsnull, aPresContext);
|
||||
|
||||
if ((nsnull != mRules) && (0 < mRules->Count())) {
|
||||
PRUint32 cnt = 0;
|
||||
if (mRules) {
|
||||
nsresult rv = mRules->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
}
|
||||
if (0 < cnt) {
|
||||
MapStyleData data(this, aPresContext);
|
||||
mRules->EnumerateForwards(MapStyleRuleFont, &data);
|
||||
mRules->EnumerateForwards(MapStyleRule, &data);
|
||||
|
|
|
@ -259,7 +259,10 @@ void StyleSetImpl::RemoveOverrideStyleSheet(nsIStyleSheet* aSheet)
|
|||
PRInt32 StyleSetImpl::GetNumberOfOverrideStyleSheets()
|
||||
{
|
||||
if (nsnull != mOverrideSheets) {
|
||||
return mOverrideSheets->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mOverrideSheets->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return 0; // XXX error?
|
||||
return cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -282,7 +285,9 @@ void StyleSetImpl::AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocumen
|
|||
mDocSheets->RemoveElement(aSheet);
|
||||
// lowest index last
|
||||
PRInt32 newDocIndex = aDocument->GetIndexOfStyleSheet(aSheet);
|
||||
PRUint32 count = mDocSheets->Count();
|
||||
PRUint32 count;
|
||||
nsresult rv = mDocSheets->Count(&count);
|
||||
if (NS_FAILED(rv)) return; // XXX error?
|
||||
PRUint32 index;
|
||||
for (index = 0; index < count; index++) {
|
||||
nsIStyleSheet* sheet = (nsIStyleSheet*)mDocSheets->ElementAt(index);
|
||||
|
@ -293,7 +298,10 @@ void StyleSetImpl::AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocumen
|
|||
}
|
||||
NS_RELEASE(sheet);
|
||||
}
|
||||
if (mDocSheets->Count() == count) { // didn't insert it
|
||||
PRUint32 cnt;
|
||||
rv = mDocSheets->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return; // XXX error?
|
||||
if (cnt == count) { // didn't insert it
|
||||
mDocSheets->AppendElement(aSheet);
|
||||
}
|
||||
|
||||
|
@ -315,7 +323,10 @@ void StyleSetImpl::RemoveDocStyleSheet(nsIStyleSheet* aSheet)
|
|||
PRInt32 StyleSetImpl::GetNumberOfDocStyleSheets()
|
||||
{
|
||||
if (nsnull != mDocSheets) {
|
||||
return mDocSheets->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mDocSheets->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return 0; // XXX error?
|
||||
return cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -374,7 +385,10 @@ void StyleSetImpl::RemoveBackstopStyleSheet(nsIStyleSheet* aSheet)
|
|||
PRInt32 StyleSetImpl::GetNumberOfBackstopStyleSheets()
|
||||
{
|
||||
if (nsnull != mBackstopSheets) {
|
||||
return mBackstopSheets->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mBackstopSheets->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return 0; // XXX error?
|
||||
return cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -398,7 +412,10 @@ PRInt32 StyleSetImpl::RulesMatching(nsISupportsArray* aSheets,
|
|||
PRInt32 ruleCount = 0;
|
||||
|
||||
if (nsnull != aSheets) {
|
||||
PRInt32 index = aSheets->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = aSheets->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
PRInt32 index = (PRInt32)cnt;
|
||||
while (0 < index--) {
|
||||
nsIStyleSheet* sheet = (nsIStyleSheet*)aSheets->ElementAt(index);
|
||||
PRBool mediumOK = PR_FALSE;
|
||||
|
@ -472,7 +489,10 @@ nsIStyleContext* StyleSetImpl::GetContext(nsIPresContext* aPresContext,
|
|||
// XXX for now only works for strength 0 & 1
|
||||
static void SortRulesByStrength(nsISupportsArray* aRules, PRInt32& aBackstopRuleCount)
|
||||
{
|
||||
PRInt32 count = aRules->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = aRules->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return; // XXX error?
|
||||
PRInt32 count = (PRInt32)cnt;
|
||||
|
||||
if (1 < count) {
|
||||
PRInt32 index;
|
||||
|
@ -583,7 +603,10 @@ PRInt32 StyleSetImpl::RulesMatching(nsISupportsArray* aSheets,
|
|||
PRInt32 ruleCount = 0;
|
||||
|
||||
if (nsnull != aSheets) {
|
||||
PRInt32 index = aSheets->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = aSheets->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
PRInt32 index = (PRInt32)cnt;
|
||||
while (0 < index--) {
|
||||
nsIStyleSheet* sheet = (nsIStyleSheet*)aSheets->ElementAt(index);
|
||||
PRBool mediumOK = PR_FALSE;
|
||||
|
@ -887,9 +910,13 @@ StyleSetImpl::CreateContinuingFrame(nsIPresContext* aPresContext,
|
|||
|
||||
void StyleSetImpl::List(FILE* out, PRInt32 aIndent, nsISupportsArray* aSheets)
|
||||
{
|
||||
PRInt32 count = ((nsnull != aSheets) ? aSheets->Count() : 0);
|
||||
PRUint32 cnt = 0;
|
||||
if (aSheets) {
|
||||
nsresult rv = aSheets->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return; // XXX error?
|
||||
}
|
||||
|
||||
for (PRInt32 index = 0; index < count; index++) {
|
||||
for (PRInt32 index = 0; index < (PRInt32)cnt; index++) {
|
||||
nsIStyleSheet* sheet = (nsIStyleSheet*)aSheets->ElementAt(index);
|
||||
sheet->List(out, aIndent);
|
||||
fputs("\n", out);
|
||||
|
|
|
@ -619,7 +619,9 @@ nsMsgAppCore::CopyMessages(nsIDOMXULElement *srcFolderElement, nsIDOMXULElement
|
|||
//And even more in the future we need to distinguish between the different types of URI's, i.e.
|
||||
//local, imap, and news, and call the appropriate copy function.
|
||||
|
||||
if(resourceArray->Count() > 0)
|
||||
PRUint32 cnt;
|
||||
rv = resourceArray->Count(&cnt);
|
||||
if (NS_SUCCEEDED(rv) && cnt > 0)
|
||||
{
|
||||
nsIRDFResource * firstMessage = (nsIRDFResource*)resourceArray->ElementAt(0);
|
||||
char *uri;
|
||||
|
|
|
@ -475,7 +475,9 @@ nsMsgFolderDataSource::IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aS
|
|||
nsresult rv;
|
||||
nsCOMPtr<nsIMsgFolder> folder;
|
||||
|
||||
PRUint32 cnt = aSources->Count();
|
||||
PRUint32 cnt;
|
||||
rv = aSources->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt; i++) {
|
||||
nsCOMPtr<nsISupports> source = getter_AddRefs((*aSources)[i]);
|
||||
folder = do_QueryInterface(source, &rv);
|
||||
|
@ -502,7 +504,9 @@ nsMsgFolderDataSource::DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
|
|||
|
||||
// XXX need to handle batching of command applied to all sources
|
||||
|
||||
PRUint32 cnt = aSources->Count();
|
||||
PRUint32 cnt;
|
||||
rv = aSources->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt; i++) {
|
||||
nsCOMPtr<nsISupports> supports = getter_AddRefs((*aSources)[i]);
|
||||
nsCOMPtr<nsIMsgFolder> folder = do_QueryInterface(supports, &rv);
|
||||
|
@ -741,12 +745,14 @@ nsMsgFolderDataSource::createFolderMessageNode(nsIMsgFolder *folder,
|
|||
nsresult nsMsgFolderDataSource::DoDeleteFromFolder(nsIMsgFolder *folder, nsISupportsArray *arguments)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
PRUint32 itemCount;
|
||||
rv = arguments->Count(&itemCount);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsISupportsArray> messageArray, folderArray;
|
||||
NS_NewISupportsArray(getter_AddRefs(messageArray));
|
||||
NS_NewISupportsArray(getter_AddRefs(folderArray));
|
||||
|
||||
PRUint32 itemCount = arguments->Count();
|
||||
|
||||
//Split up deleted items into different type arrays to be passed to the folder
|
||||
//for deletion.
|
||||
for(PRUint32 item = 0; item < itemCount; item++)
|
||||
|
@ -763,7 +769,10 @@ nsresult nsMsgFolderDataSource::DoDeleteFromFolder(nsIMsgFolder *folder, nsISupp
|
|||
folderArray->AppendElement(deletedFolder);
|
||||
}
|
||||
}
|
||||
if(messageArray->Count() > 0)
|
||||
PRUint32 cnt;
|
||||
rv = messageArray->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (cnt > 0)
|
||||
rv = folder->DeleteMessages(messageArray);
|
||||
|
||||
return rv;
|
||||
|
@ -833,4 +842,4 @@ nsresult nsMsgFolderDataSource::DoFolderHasAssertion(nsIMsgFolder *folder, nsIRD
|
|||
return rv;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -383,7 +383,9 @@ nsMsgMessageDataSource::IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* a
|
|||
nsCOMPtr<nsIMessage> message;
|
||||
nsresult rv;
|
||||
|
||||
PRUint32 cnt = aSources->Count();
|
||||
PRUint32 cnt;
|
||||
rv = aSources->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt; i++) {
|
||||
nsCOMPtr<nsISupports> source = getter_AddRefs((*aSources)[i]);
|
||||
message = do_QueryInterface(source, &rv);
|
||||
|
@ -407,7 +409,9 @@ nsMsgMessageDataSource::DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources
|
|||
|
||||
// XXX need to handle batching of command applied to all sources
|
||||
|
||||
PRUint32 cnt = aSources->Count();
|
||||
PRUint32 cnt;
|
||||
rv = aSources->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt; i++) {
|
||||
nsISupports* source = (*aSources)[i];
|
||||
nsCOMPtr<nsIMessage> message = do_QueryInterface(source, &rv);
|
||||
|
|
|
@ -88,17 +88,19 @@ nsMsgFolder::~nsMsgFolder(void)
|
|||
{
|
||||
if(mSubFolders)
|
||||
{
|
||||
PRUint32 count = mSubFolders->Count();
|
||||
PRUint32 count;
|
||||
nsresult rv = mSubFolders->Count(&count);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
|
||||
for (int i = count - 1; i >= 0; i--)
|
||||
mSubFolders->RemoveElementAt(i);
|
||||
}
|
||||
|
||||
if (mListeners) {
|
||||
for (PRInt32 i = mListeners->Count() - 1; i >= 0; --i) {
|
||||
mListeners->RemoveElementAt(i);
|
||||
}
|
||||
delete mListeners;
|
||||
for (PRInt32 i = mListeners->Count() - 1; i >= 0; --i) {
|
||||
mListeners->RemoveElementAt(i);
|
||||
}
|
||||
delete mListeners;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -136,7 +138,10 @@ nsFilterBy(nsISupportsArray* array, nsArrayFilter filter, void* data,
|
|||
nsCOMPtr<nsISupportsArray> f;
|
||||
nsresult rv = NS_NewISupportsArray(getter_AddRefs(f));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < array->Count(); i++) {
|
||||
PRUint32 cnt;
|
||||
rv = array->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt; i++) {
|
||||
nsCOMPtr<nsISupports> element = getter_AddRefs((*array)[i]);
|
||||
if (filter(element, data)) {
|
||||
rv = f->AppendElement(element);
|
||||
|
@ -179,7 +184,10 @@ nsMsgFolder::GetSubFolders(nsIEnumerator* *result)
|
|||
NS_IMETHODIMP
|
||||
nsMsgFolder::GetHasSubFolders(PRBool *_retval)
|
||||
{
|
||||
*_retval = (mSubFolders->Count() > 0);
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mSubFolders->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
*_retval = (cnt > 0);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -296,33 +304,6 @@ NS_IMETHODIMP nsMsgFolder::SetPrettyName(char *name)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRUint32) nsMsgFolder::Count(void)
|
||||
{
|
||||
return mSubFolders->Count();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgFolder::AppendElement(nsISupports *aElement)
|
||||
{
|
||||
return mSubFolders->AppendElement(aElement);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgFolder::RemoveElement(nsISupports *aElement)
|
||||
{
|
||||
return mSubFolders->RemoveElement(aElement);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsMsgFolder::Enumerate(nsIEnumerator* *result)
|
||||
{
|
||||
// nsMsgFolders only have subfolders, no message elements
|
||||
return mSubFolders->Enumerate(result);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgFolder::Clear(void)
|
||||
{
|
||||
return mSubFolders->Clear();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgFolder::GetName(char **name)
|
||||
{
|
||||
char *cmName = mName.ToNewCString();
|
||||
|
@ -435,7 +416,10 @@ NS_IMETHODIMP nsMsgFolder::PropagateDelete(nsIMsgFolder **folder, PRBool deleteS
|
|||
nsCOMPtr<nsIMsgFolder> child;
|
||||
|
||||
// first, find the folder we're looking to delete
|
||||
for (PRUint32 i = 0; i < mSubFolders->Count() && *folder; i++)
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mSubFolders->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt && *folder; i++)
|
||||
{
|
||||
nsCOMPtr<nsISupports> supports = getter_AddRefs(mSubFolders->ElementAt(i));
|
||||
child = do_QueryInterface(supports, &status);
|
||||
|
@ -484,7 +468,10 @@ NS_IMETHODIMP nsMsgFolder::RecursiveDelete(PRBool deleteStorage)
|
|||
|
||||
nsresult status = NS_OK;
|
||||
|
||||
while (mSubFolders->Count() > 0)
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mSubFolders->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
while (cnt > 0)
|
||||
{
|
||||
nsCOMPtr<nsISupports> supports = getter_AddRefs(mSubFolders->ElementAt(0));
|
||||
nsCOMPtr<nsIMsgFolder> child(do_QueryInterface(supports, &status));
|
||||
|
@ -562,7 +549,9 @@ NS_IMETHODIMP nsMsgFolder::IsAncestorOf(nsIMsgFolder *child, PRBool *isAncestor)
|
|||
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
PRUint32 count = mSubFolders->Count();
|
||||
PRUint32 count;
|
||||
rv = mSubFolders->Count(&count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
for (PRUint32 i = 0; i < count; i++)
|
||||
{
|
||||
|
@ -665,20 +654,23 @@ NS_IMETHODIMP nsMsgFolder::GetNumUnread(PRBool deep, PRInt32 *numUnread)
|
|||
if (deep)
|
||||
{
|
||||
nsCOMPtr<nsIMsgFolder> folder;
|
||||
PRUint32 count = mSubFolders->Count();
|
||||
PRUint32 count;
|
||||
rv = mSubFolders->Count(&count);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
||||
for (PRUint32 i = 0; i < count; i++)
|
||||
{
|
||||
nsCOMPtr<nsISupports> supports = getter_AddRefs(mSubFolders->ElementAt(i));
|
||||
folder = do_QueryInterface(supports, &rv);
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
PRInt32 num;
|
||||
folder->GetNumUnread(deep, &num);
|
||||
if (num >= 0) // it's legal for counts to be negative if we don't know
|
||||
total += num;
|
||||
}
|
||||
}
|
||||
for (PRUint32 i = 0; i < count; i++)
|
||||
{
|
||||
nsCOMPtr<nsISupports> supports = getter_AddRefs(mSubFolders->ElementAt(i));
|
||||
folder = do_QueryInterface(supports, &rv);
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
PRInt32 num;
|
||||
folder->GetNumUnread(deep, &num);
|
||||
if (num >= 0) // it's legal for counts to be negative if we don't know
|
||||
total += num;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*numUnread = total;
|
||||
return NS_OK;
|
||||
|
@ -695,18 +687,21 @@ NS_IMETHODIMP nsMsgFolder::GetTotalMessages(PRBool deep, PRInt32 *totalMessages)
|
|||
if (deep)
|
||||
{
|
||||
nsCOMPtr<nsIMsgFolder> folder;
|
||||
PRUint32 count = mSubFolders->Count();
|
||||
PRUint32 count;
|
||||
rv = mSubFolders->Count(&count);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
||||
for (PRUint32 i = 0; i < count; i++)
|
||||
{
|
||||
nsCOMPtr<nsISupports> supports = getter_AddRefs(mSubFolders->ElementAt(i));
|
||||
folder = do_QueryInterface(supports, &rv);
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
PRInt32 num;
|
||||
folder->GetTotalMessages (deep, &num);
|
||||
if (num >= 0) // it's legal for counts to be negative if we don't know
|
||||
total += num;
|
||||
for (PRUint32 i = 0; i < count; i++)
|
||||
{
|
||||
nsCOMPtr<nsISupports> supports = getter_AddRefs(mSubFolders->ElementAt(i));
|
||||
folder = do_QueryInterface(supports, &rv);
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
PRInt32 num;
|
||||
folder->GetTotalMessages (deep, &num);
|
||||
if (num >= 0) // it's legal for counts to be negative if we don't know
|
||||
total += num;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -842,33 +837,36 @@ NS_IMETHODIMP nsMsgFolder::GetFoldersWithFlag(PRUint32 flags, nsIMsgFolder **res
|
|||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIMsgFolder> folder;
|
||||
for (PRUint32 i=0; i < (PRUint32)mSubFolders->Count(); i++) {
|
||||
nsCOMPtr<nsISupports> supports = getter_AddRefs(mSubFolders->ElementAt(i));
|
||||
folder = do_QueryInterface(supports, &rv);
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
// CAREFUL! if NULL is passed in for result then the caller
|
||||
// still wants the full count! Otherwise, the result should be at most the
|
||||
// number that the caller asked for.
|
||||
PRUint32 numSubFolders;
|
||||
|
||||
if (!result)
|
||||
{
|
||||
folder->GetFoldersWithFlag(flags, NULL, 0, &numSubFolders);
|
||||
num += numSubFolders;
|
||||
}
|
||||
else if (num < resultsize)
|
||||
{
|
||||
folder->GetFoldersWithFlag(flags, result + num, resultsize - num, &numSubFolders);
|
||||
num += numSubFolders;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
PRUint32 cnt;
|
||||
rv = mSubFolders->Count(&cnt);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
for (PRUint32 i=0; i < cnt; i++) {
|
||||
nsCOMPtr<nsISupports> supports = getter_AddRefs(mSubFolders->ElementAt(i));
|
||||
folder = do_QueryInterface(supports, &rv);
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
// CAREFUL! if NULL is passed in for result then the caller
|
||||
// still wants the full count! Otherwise, the result should be at most the
|
||||
// number that the caller asked for.
|
||||
PRUint32 numSubFolders;
|
||||
|
||||
if (!result)
|
||||
{
|
||||
folder->GetFoldersWithFlag(flags, NULL, 0, &numSubFolders);
|
||||
num += numSubFolders;
|
||||
}
|
||||
else if (num < resultsize)
|
||||
{
|
||||
folder->GetFoldersWithFlag(flags, result + num, resultsize - num, &numSubFolders);
|
||||
num += numSubFolders;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*numFolders = num;
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -879,18 +877,25 @@ NS_IMETHODIMP nsMsgFolder::GetExpansionArray(nsISupportsArray *expansionArray)
|
|||
// than in GetFoldersWithFlag
|
||||
|
||||
nsresult rv;
|
||||
for (PRUint32 i = 0; i < mSubFolders->Count(); i++)
|
||||
PRUint32 cnt;
|
||||
rv = mSubFolders->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt; i++)
|
||||
{
|
||||
nsCOMPtr<nsISupports> supports = getter_AddRefs(mSubFolders->ElementAt(i));
|
||||
nsCOMPtr<nsIMsgFolder> folder = do_QueryInterface(supports, &rv);
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
expansionArray->InsertElementAt(folder, expansionArray->Count());
|
||||
PRUint32 flags;
|
||||
folder->GetFlags(&flags);
|
||||
if (!(flags & MSG_FOLDER_FLAG_ELIDED))
|
||||
folder->GetExpansionArray(expansionArray);
|
||||
}
|
||||
PRUint32 cnt;
|
||||
nsresult rv = expansionArray->Count(&cnt);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
expansionArray->InsertElementAt(folder, cnt);
|
||||
PRUint32 flags;
|
||||
folder->GetFlags(&flags);
|
||||
if (!(flags & MSG_FOLDER_FLAG_ELIDED))
|
||||
folder->GetExpansionArray(expansionArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
@ -45,11 +45,28 @@ public:
|
|||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsICollection methods:
|
||||
NS_IMETHOD_(PRUint32) Count(void);
|
||||
NS_IMETHOD AppendElement(nsISupports *aElement);
|
||||
NS_IMETHOD RemoveElement(nsISupports *aElement);
|
||||
NS_IMETHOD Enumerate(nsIEnumerator* *result);
|
||||
NS_IMETHOD Clear(void);
|
||||
NS_IMETHOD Count(PRUint32 *result) {
|
||||
return mSubFolders->Count(result);
|
||||
}
|
||||
NS_IMETHOD GetElementAt(PRUint32 index, nsISupports* *result) {
|
||||
return mSubFolders->GetElementAt(index, result);
|
||||
}
|
||||
NS_IMETHOD SetElementAt(PRUint32 index, nsISupports* value) {
|
||||
return mSubFolders->SetElementAt(index, value);
|
||||
}
|
||||
NS_IMETHOD AppendElement(nsISupports *aElement) {
|
||||
return mSubFolders->AppendElement(aElement);
|
||||
}
|
||||
NS_IMETHOD RemoveElement(nsISupports *aElement) {
|
||||
return mSubFolders->RemoveElement(aElement);
|
||||
}
|
||||
NS_IMETHOD Enumerate(nsIEnumerator* *result) {
|
||||
// nsMsgFolders only have subfolders, no message elements
|
||||
return mSubFolders->Enumerate(result);
|
||||
}
|
||||
NS_IMETHOD Clear(void) {
|
||||
return mSubFolders->Clear();
|
||||
}
|
||||
|
||||
// nsIFolder methods:
|
||||
NS_IMETHOD GetURI(char* *name) { return nsRDFResource::GetValue(name); }
|
||||
|
|
|
@ -841,7 +841,9 @@ NS_IMETHODIMP nsImapMailFolder::DeleteMessages(nsISupportsArray *messages)
|
|||
}
|
||||
if(NS_SUCCEEDED(rv) && trashFolder)
|
||||
{
|
||||
PRUint32 count = messages->Count();
|
||||
PRUint32 count = 0;
|
||||
rv = messages->Count(&count);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
nsString2 messageIds("", eOneByte);
|
||||
for (PRUint32 i = 0; i < count; i++)
|
||||
{
|
||||
|
|
|
@ -114,7 +114,10 @@ nsImapService::CreateImapConnection(nsIEventQueue *aEventQueue, nsIImapUrl * aIm
|
|||
PRBool canRunUrl = PR_FALSE;
|
||||
nsCOMPtr<nsIImapProtocol> connection;
|
||||
// iterate through the connection cache for a connection that can handle this url.
|
||||
for (PRUint32 i = 0; i < m_connectionCache->Count() && !canRunUrl; i++)
|
||||
PRUint32 cnt;
|
||||
rv = m_connectionCache->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt && !canRunUrl; i++)
|
||||
{
|
||||
connection = do_QueryInterface(m_connectionCache->ElementAt(i));
|
||||
if (connection)
|
||||
|
|
|
@ -704,7 +704,9 @@ nsMsgLocalMailFolder::GetChildNamed(const char *name, nsISupports ** aChild)
|
|||
|
||||
nsCOMPtr<nsIMsgFolder> folder;
|
||||
|
||||
PRUint32 count = mSubFolders->Count();
|
||||
PRUint32 count;
|
||||
rv = mSubFolders->Count(&count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
for (PRUint32 i = 0; i < count; i++)
|
||||
{
|
||||
|
@ -1046,7 +1048,9 @@ NS_IMETHODIMP nsMsgLocalMailFolder::DeleteMessages(nsISupportsArray *messages)
|
|||
nsresult rv = GetDatabase();
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
PRUint32 messageCount = messages->Count();
|
||||
PRUint32 messageCount;
|
||||
rv = messages->Count(&messageCount);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for(PRUint32 i = 0; i < messageCount; i++)
|
||||
{
|
||||
nsCOMPtr<nsISupports> msgSupports = getter_AddRefs(messages->ElementAt(i));
|
||||
|
|
|
@ -70,7 +70,10 @@ static char *nsMailboxGetURI(char *nativepath)
|
|||
// do a char*->fileSpec->char* conversion to normalize the path
|
||||
nsFilePath filePath(nativepath);
|
||||
|
||||
PRInt32 count = serverArray->Count();
|
||||
PRUint32 cnt;
|
||||
rv = serverArray->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return nsnull;
|
||||
PRInt32 count = cnt;
|
||||
PRInt32 i;
|
||||
for (i=0; i<count; i++) {
|
||||
|
||||
|
|
|
@ -2012,7 +2012,10 @@ nsNNTPHost::FindGroup(const char* name, nsINNTPNewsgroup* *retval)
|
|||
#endif
|
||||
|
||||
if (m_groups == NULL) return result;
|
||||
int n = m_groups->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = m_groups->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
int n = cnt;
|
||||
for (int i=0 ; i<n ; i++) {
|
||||
char *groupname = nsnull;
|
||||
nsresult rv = NS_OK;
|
||||
|
@ -2119,8 +2122,11 @@ nsNNTPHost::AddGroup(const char *name,
|
|||
|
||||
if (m_groups != nsnull) {
|
||||
// groups are added at end so look there first...
|
||||
PRUint32 cnt;
|
||||
nsresult rv = m_groups->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
newsInfo = (nsINNTPNewsgroup *)
|
||||
(*m_groups)[m_groups->Count() - 1];
|
||||
(*m_groups)[cnt - 1];
|
||||
}
|
||||
|
||||
if (!newsInfo) goto DONE;
|
||||
|
@ -2395,7 +2401,10 @@ nsresult
|
|||
nsNNTPHost::GetNumGroupsNeedingCounts(PRInt32 *value)
|
||||
{
|
||||
if (!m_groups) return NS_ERROR_NOT_INITIALIZED;
|
||||
int num = m_groups->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = m_groups->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
int num = cnt;
|
||||
PRInt32 result = 0;
|
||||
for (int i=0 ; i<num ; i++) {
|
||||
nsINNTPNewsgroup* info = (nsINNTPNewsgroup*) ((*m_groups)[i]);
|
||||
|
@ -2418,7 +2427,10 @@ nsresult
|
|||
nsNNTPHost::GetFirstGroupNeedingCounts(char **result)
|
||||
{
|
||||
if (!m_groups) return NS_ERROR_NULL_POINTER;
|
||||
int num = m_groups->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = m_groups->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
int num = cnt;
|
||||
for (int i=0 ; i<num ; i++) {
|
||||
nsINNTPNewsgroup* info = (nsINNTPNewsgroup*) ((*m_groups)[i]);
|
||||
|
||||
|
@ -2468,7 +2480,10 @@ void
|
|||
nsNNTPHost::SetWantNewTotals(PRBool value)
|
||||
{
|
||||
if (!m_groups) return;
|
||||
int n = m_groups->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = m_groups->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return; // XXX error?
|
||||
int n = cnt;
|
||||
for (int i=0 ; i<n ; i++) {
|
||||
nsINNTPNewsgroup* info = (nsINNTPNewsgroup*) ((*m_groups)[i]);
|
||||
info->SetWantNewTotals(value);
|
||||
|
@ -3401,7 +3416,10 @@ int nsNNTPHost::ReorderGroup(nsINNTPNewsgroup *groupToMove, nsINNTPNewsgroup *gr
|
|||
infoList->First();
|
||||
PRBool foundIdxInHostInfo = PR_FALSE;
|
||||
|
||||
for (idxInData = 0, idxInView = -1; idxInData < (PRInt32)m_groups->Count(); idxInData++)
|
||||
PRUint32 cnt;
|
||||
nsresult rv = m_groups->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (idxInData = 0, idxInView = -1; idxInData < (PRInt32)cnt; idxInData++)
|
||||
{
|
||||
group = (nsIMsgFolder*)(*m_groups)[idxInData];
|
||||
|
||||
|
@ -3491,7 +3509,10 @@ nsNNTPHost::GetNewsgroupList(const char* name, nsINNTPNewsgroupList **retval)
|
|||
#endif
|
||||
|
||||
if (m_newsgrouplists == NULL) return result;
|
||||
int n = m_newsgrouplists->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = m_newsgrouplists->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
int n = cnt;
|
||||
for (int i=0 ; i<n ; i++) {
|
||||
char *newsgroupname = nsnull;
|
||||
nsresult rv = NS_OK;
|
||||
|
|
|
@ -721,7 +721,10 @@ nsMsgNewsFolder::GetChildNamed(const char *name, nsISupports ** aChild)
|
|||
|
||||
nsIMsgFolder *folder = nsnull;
|
||||
|
||||
PRUint32 count = mSubFolders->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mSubFolders->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
PRUint32 count = cnt;
|
||||
|
||||
for (PRUint32 i = 0; i < count; i++)
|
||||
{
|
||||
|
|
|
@ -219,7 +219,10 @@ nsRDFDOMNodeList::GetLength(PRUint32* aLength)
|
|||
if (! aLength)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aLength = mElements->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mElements->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
*aLength = cnt;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -231,8 +234,11 @@ nsRDFDOMNodeList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
|
|||
if (! aReturn)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(aIndex < (PRUint32) mElements->Count(), "invalid arg");
|
||||
if (aIndex >= (PRUint32) mElements->Count())
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mElements->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
NS_PRECONDITION(aIndex < cnt, "invalid arg");
|
||||
if (aIndex >= (PRUint32) cnt)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
// Cast is okay because we're in a closed system.
|
||||
|
|
|
@ -1394,7 +1394,10 @@ RDFElementImpl::SetDocument(nsIDocument* aDocument, PRBool aDeep)
|
|||
}
|
||||
|
||||
if (aDeep && mChildren) {
|
||||
for (PRInt32 i = mChildren->Count() - 1; i >= 0; --i) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mChildren->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRInt32 i = cnt - 1; i >= 0; --i) {
|
||||
// XXX this entire block could be more rigorous about
|
||||
// dealing with failure.
|
||||
nsISupports* obj = mChildren->ElementAt(i);
|
||||
|
@ -1445,7 +1448,14 @@ RDFElementImpl::ChildCount(PRInt32& aResult) const
|
|||
if (NS_FAILED(rv = EnsureContentsGenerated()))
|
||||
return rv;
|
||||
|
||||
aResult = mChildren ? mChildren->Count() : 0;
|
||||
if (mChildren) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mChildren->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
aResult = cnt;
|
||||
}
|
||||
else
|
||||
aResult = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1574,7 +1584,10 @@ RDFElementImpl::AppendChildTo(nsIContent* aKid, PRBool aNotify)
|
|||
if (nsnull != doc) {
|
||||
aKid->SetDocument(doc, PR_TRUE);
|
||||
if (aNotify) {
|
||||
doc->ContentInserted(NS_STATIC_CAST(nsIStyledContent*, this), aKid, mChildren->Count() - 1);
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mChildren->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
doc->ContentInserted(NS_STATIC_CAST(nsIStyledContent*, this), aKid, cnt - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -553,16 +553,19 @@ RDFGenericBuilderImpl::CreateContents(nsIContent* aElement)
|
|||
}
|
||||
}
|
||||
|
||||
unsigned long numElements = tempArray->Count();
|
||||
if (numElements > 0)
|
||||
PRUint32 cnt = 0;
|
||||
rv = tempArray->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
unsigned long numElements = cnt;
|
||||
if (numElements > 0)
|
||||
{
|
||||
nsIRDFResource ** flatArray = new nsIRDFResource *[numElements];
|
||||
if (flatArray)
|
||||
{
|
||||
nsIRDFResource ** flatArray = new nsIRDFResource *[numElements];
|
||||
if (flatArray)
|
||||
{
|
||||
// flatten array of resources, sort them, then add as item elements
|
||||
unsigned long loop;
|
||||
|
||||
for (loop=0; loop<numElements; loop++)
|
||||
for (loop=0; loop<numElements; loop++)
|
||||
flatArray[loop] = (nsIRDFResource *)tempArray->ElementAt(loop);
|
||||
|
||||
if (nsnull != XULSortService)
|
||||
|
@ -570,26 +573,26 @@ RDFGenericBuilderImpl::CreateContents(nsIContent* aElement)
|
|||
XULSortService->OpenContainer(mDB, aElement, flatArray, numElements/2, 2*sizeof(nsIRDFResource *));
|
||||
}
|
||||
|
||||
for (loop=0; loop<numElements; loop+=2)
|
||||
{
|
||||
for (loop=0; loop<numElements; loop+=2)
|
||||
{
|
||||
if (NS_FAILED(rv = CreateWidgetItem(aElement, flatArray[loop+1], flatArray[loop], loop+1)))
|
||||
{
|
||||
NS_ERROR("unable to create widget item");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = numElements - 1; i >=0; i--)
|
||||
{
|
||||
for (int i = numElements - 1; i >=0; i--)
|
||||
{
|
||||
NS_IF_RELEASE(flatArray[i]);
|
||||
}
|
||||
}
|
||||
delete [] flatArray;
|
||||
}
|
||||
}
|
||||
for (int i = numElements - 1; i >= 0; i--)
|
||||
{
|
||||
tempArray->RemoveElementAt(i);
|
||||
}
|
||||
NS_IF_RELEASE(tempArray);
|
||||
}
|
||||
for (int i = numElements - 1; i >= 0; i--)
|
||||
{
|
||||
tempArray->RemoveElementAt(i);
|
||||
}
|
||||
NS_IF_RELEASE(tempArray);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -1053,7 +1056,10 @@ RDFGenericBuilderImpl::OnAssert(nsIRDFResource* aSubject,
|
|||
return rv;
|
||||
}
|
||||
|
||||
for (PRInt32 i = elements->Count() - 1; i >= 0; --i) {
|
||||
PRUint32 cnt = 0;
|
||||
rv = elements->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
for (PRInt32 i = cnt - 1; i >= 0; --i) {
|
||||
nsCOMPtr<nsIContent> element( do_QueryInterface(elements->ElementAt(i)) );
|
||||
|
||||
// XXX somehow figure out if building XUL kids on this
|
||||
|
@ -1137,7 +1143,10 @@ RDFGenericBuilderImpl::OnUnassert(nsIRDFResource* aSubject,
|
|||
return rv;
|
||||
}
|
||||
|
||||
for (PRInt32 i = elements->Count() - 1; i >= 0; --i) {
|
||||
PRUint32 cnt = 0;
|
||||
rv = elements->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
for (PRInt32 i = cnt - 1; i >= 0; --i) {
|
||||
nsCOMPtr<nsIContent> element( do_QueryInterface(elements->ElementAt(i)) );
|
||||
|
||||
// XXX somehow figure out if building XUL kids on this
|
||||
|
|
|
@ -521,7 +521,10 @@ RDFTreeBuilderImpl::CheckRDFGraphForUpdates(nsIContent *container)
|
|||
}
|
||||
}
|
||||
|
||||
PRInt32 numElements = childArray->Count();
|
||||
PRUint32 cnt = 0;
|
||||
rv = childArray->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
PRInt32 numElements = cnt;
|
||||
if (numElements > 0)
|
||||
{
|
||||
nsIRDFResource ** flatArray = new nsIRDFResource*[numElements];
|
||||
|
@ -624,10 +627,12 @@ RDFTreeBuilderImpl::CheckRDFGraphForUpdates(nsIContent *container)
|
|||
flatArray = nsnull;
|
||||
}
|
||||
}
|
||||
for (int i = childArray->Count() - 1; i >= 0; i--)
|
||||
{
|
||||
childArray->RemoveElementAt(i);
|
||||
}
|
||||
rv = childArray->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (int i = cnt - 1; i >= 0; i--)
|
||||
{
|
||||
childArray->RemoveElementAt(i);
|
||||
}
|
||||
return(NS_OK);
|
||||
}
|
||||
|
||||
|
|
|
@ -785,7 +785,10 @@ RDFXULBuilderImpl::OnAssert(nsIRDFResource* aSource,
|
|||
return rv;
|
||||
}
|
||||
|
||||
for (PRInt32 i = elements->Count() - 1; i >= 0; --i) {
|
||||
PRUint32 cnt = 0;
|
||||
rv = elements->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
for (PRInt32 i = cnt - 1; i >= 0; --i) {
|
||||
nsCOMPtr<nsIContent> element( do_QueryInterface(elements->ElementAt(i)) );
|
||||
|
||||
// XXX Make sure that the element we're looking at is really
|
||||
|
@ -894,7 +897,10 @@ RDFXULBuilderImpl::OnUnassert(nsIRDFResource* aSource,
|
|||
return rv;
|
||||
}
|
||||
|
||||
for (PRInt32 i = elements->Count() - 1; i >= 0; --i) {
|
||||
PRUint32 cnt = 0;
|
||||
rv = elements->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
for (PRInt32 i = cnt - 1; i >= 0; --i) {
|
||||
nsCOMPtr<nsIContent> element( do_QueryInterface(elements->ElementAt(i)) );
|
||||
|
||||
// XXX somehow figure out if removing XUL kids from this
|
||||
|
|
|
@ -839,12 +839,15 @@ XULDocumentImpl::~XULDocumentImpl()
|
|||
// to break ownership cycle
|
||||
if (mBuilders)
|
||||
{
|
||||
PRUint32 cnt = 0;
|
||||
nsresult rv = mBuilders->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("# of builders: %lu\n", (unsigned long)mBuilders->Count());
|
||||
printf("# of builders: %lu\n", (unsigned long)cnt);
|
||||
#endif
|
||||
|
||||
for (PRUint32 i = 0; i < mBuilders->Count(); ++i)
|
||||
for (PRUint32 i = 0; i < cnt; ++i)
|
||||
{
|
||||
// XXX we should QueryInterface() here
|
||||
nsIRDFContentModelBuilder* builder
|
||||
|
@ -2311,7 +2314,10 @@ XULDocumentImpl::CreateContents(nsIContent* aElement)
|
|||
if (! mBuilders)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
||||
PRUint32 cnt = 0;
|
||||
nsresult rv = mBuilders->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
for (PRUint32 i = 0; i < cnt; ++i) {
|
||||
// XXX we should QueryInterface() here
|
||||
nsIRDFContentModelBuilder* builder
|
||||
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
||||
|
@ -2710,8 +2716,11 @@ XULDocumentImpl::GetElementById(const nsString& aId, nsIDOMElement** aReturn)
|
|||
return rv;
|
||||
}
|
||||
|
||||
if (elements->Count() > 0) {
|
||||
if (elements->Count() > 1) {
|
||||
PRUint32 cnt = 0;
|
||||
rv = elements->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
if (cnt > 0) {
|
||||
if (cnt > 1) {
|
||||
// This is a scary case that our API doesn't deal with well.
|
||||
NS_WARNING("more than one element found with specified ID; returning first");
|
||||
}
|
||||
|
@ -3197,7 +3206,10 @@ XULDocumentImpl::GetInlineStyleSheet(nsIHTMLCSSStyleSheet** aResult)
|
|||
NS_IMETHODIMP
|
||||
XULDocumentImpl::OnSetNodeValue(nsIDOMNode* aNode, const nsString& aValue)
|
||||
{
|
||||
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mBuilders->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt; ++i) {
|
||||
nsIRDFContentModelBuilder* builder
|
||||
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
||||
|
||||
|
@ -3217,7 +3229,10 @@ XULDocumentImpl::OnSetNodeValue(nsIDOMNode* aNode, const nsString& aValue)
|
|||
NS_IMETHODIMP
|
||||
XULDocumentImpl::OnInsertBefore(nsIDOMNode* aParent, nsIDOMNode* aNewChild, nsIDOMNode* aRefChild)
|
||||
{
|
||||
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mBuilders->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt; ++i) {
|
||||
nsIRDFContentModelBuilder* builder
|
||||
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
||||
|
||||
|
@ -3237,7 +3252,10 @@ XULDocumentImpl::OnInsertBefore(nsIDOMNode* aParent, nsIDOMNode* aNewChild, nsID
|
|||
NS_IMETHODIMP
|
||||
XULDocumentImpl::OnReplaceChild(nsIDOMNode* aParent, nsIDOMNode* aNewChild, nsIDOMNode* aOldChild)
|
||||
{
|
||||
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mBuilders->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt; ++i) {
|
||||
nsIRDFContentModelBuilder* builder
|
||||
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
||||
|
||||
|
@ -3257,7 +3275,10 @@ XULDocumentImpl::OnReplaceChild(nsIDOMNode* aParent, nsIDOMNode* aNewChild, nsID
|
|||
NS_IMETHODIMP
|
||||
XULDocumentImpl::OnRemoveChild(nsIDOMNode* aParent, nsIDOMNode* aOldChild)
|
||||
{
|
||||
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mBuilders->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt; ++i) {
|
||||
nsIRDFContentModelBuilder* builder
|
||||
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
||||
|
||||
|
@ -3277,7 +3298,10 @@ XULDocumentImpl::OnRemoveChild(nsIDOMNode* aParent, nsIDOMNode* aOldChild)
|
|||
NS_IMETHODIMP
|
||||
XULDocumentImpl::OnAppendChild(nsIDOMNode* aParent, nsIDOMNode* aNewChild)
|
||||
{
|
||||
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mBuilders->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt; ++i) {
|
||||
nsIRDFContentModelBuilder* builder
|
||||
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
||||
|
||||
|
@ -3300,7 +3324,10 @@ XULDocumentImpl::OnAppendChild(nsIDOMNode* aParent, nsIDOMNode* aNewChild)
|
|||
NS_IMETHODIMP
|
||||
XULDocumentImpl::OnSetAttribute(nsIDOMElement* aElement, const nsString& aName, const nsString& aValue)
|
||||
{
|
||||
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mBuilders->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt; ++i) {
|
||||
nsIRDFContentModelBuilder* builder
|
||||
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
||||
|
||||
|
@ -3318,7 +3345,10 @@ XULDocumentImpl::OnSetAttribute(nsIDOMElement* aElement, const nsString& aName,
|
|||
NS_IMETHODIMP
|
||||
XULDocumentImpl::OnRemoveAttribute(nsIDOMElement* aElement, const nsString& aName)
|
||||
{
|
||||
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mBuilders->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt; ++i) {
|
||||
nsIRDFContentModelBuilder* builder
|
||||
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
||||
|
||||
|
@ -3336,7 +3366,10 @@ XULDocumentImpl::OnRemoveAttribute(nsIDOMElement* aElement, const nsString& aNam
|
|||
NS_IMETHODIMP
|
||||
XULDocumentImpl::OnSetAttributeNode(nsIDOMElement* aElement, nsIDOMAttr* aNewAttr)
|
||||
{
|
||||
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mBuilders->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt; ++i) {
|
||||
nsIRDFContentModelBuilder* builder
|
||||
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
||||
|
||||
|
@ -3354,7 +3387,10 @@ XULDocumentImpl::OnSetAttributeNode(nsIDOMElement* aElement, nsIDOMAttr* aNewAtt
|
|||
NS_IMETHODIMP
|
||||
XULDocumentImpl::OnRemoveAttributeNode(nsIDOMElement* aElement, nsIDOMAttr* aOldAttr)
|
||||
{
|
||||
for (PRUint32 i = 0; i < mBuilders->Count(); ++i) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mBuilders->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRUint32 i = 0; i < cnt; ++i) {
|
||||
nsIRDFContentModelBuilder* builder
|
||||
= (nsIRDFContentModelBuilder*) mBuilders->ElementAt(i);
|
||||
|
||||
|
|
|
@ -1394,7 +1394,10 @@ RDFElementImpl::SetDocument(nsIDocument* aDocument, PRBool aDeep)
|
|||
}
|
||||
|
||||
if (aDeep && mChildren) {
|
||||
for (PRInt32 i = mChildren->Count() - 1; i >= 0; --i) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mChildren->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (PRInt32 i = cnt - 1; i >= 0; --i) {
|
||||
// XXX this entire block could be more rigorous about
|
||||
// dealing with failure.
|
||||
nsISupports* obj = mChildren->ElementAt(i);
|
||||
|
@ -1445,7 +1448,14 @@ RDFElementImpl::ChildCount(PRInt32& aResult) const
|
|||
if (NS_FAILED(rv = EnsureContentsGenerated()))
|
||||
return rv;
|
||||
|
||||
aResult = mChildren ? mChildren->Count() : 0;
|
||||
if (mChildren) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mChildren->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
aResult = cnt;
|
||||
}
|
||||
else
|
||||
aResult = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1574,7 +1584,10 @@ RDFElementImpl::AppendChildTo(nsIContent* aKid, PRBool aNotify)
|
|||
if (nsnull != doc) {
|
||||
aKid->SetDocument(doc, PR_TRUE);
|
||||
if (aNotify) {
|
||||
doc->ContentInserted(NS_STATIC_CAST(nsIStyledContent*, this), aKid, mChildren->Count() - 1);
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mChildren->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
doc->ContentInserted(NS_STATIC_CAST(nsIStyledContent*, this), aKid, cnt - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -855,7 +855,10 @@ XULSortServiceImpl::SortTreeChildren(nsIContent *container, PRInt32 colIndex, so
|
|||
}
|
||||
}
|
||||
}
|
||||
unsigned long numElements = childArray->Count();
|
||||
PRUint32 cnt = 0;
|
||||
rv = childArray->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
unsigned long numElements = cnt;
|
||||
if (numElements > 0)
|
||||
{
|
||||
nsIContent ** flatArray = new nsIContent*[numElements];
|
||||
|
@ -943,10 +946,12 @@ XULSortServiceImpl::SortTreeChildren(nsIContent *container, PRInt32 colIndex, so
|
|||
flatArray = nsnull;
|
||||
}
|
||||
}
|
||||
for (int i = childArray->Count() - 1; i >= 0; i--)
|
||||
{
|
||||
childArray->RemoveElementAt(i);
|
||||
}
|
||||
rv = childArray->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (int i = cnt - 1; i >= 0; i--)
|
||||
{
|
||||
childArray->RemoveElementAt(i);
|
||||
}
|
||||
return(NS_OK);
|
||||
}
|
||||
|
||||
|
|
|
@ -553,16 +553,19 @@ RDFGenericBuilderImpl::CreateContents(nsIContent* aElement)
|
|||
}
|
||||
}
|
||||
|
||||
unsigned long numElements = tempArray->Count();
|
||||
if (numElements > 0)
|
||||
PRUint32 cnt = 0;
|
||||
rv = tempArray->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
unsigned long numElements = cnt;
|
||||
if (numElements > 0)
|
||||
{
|
||||
nsIRDFResource ** flatArray = new nsIRDFResource *[numElements];
|
||||
if (flatArray)
|
||||
{
|
||||
nsIRDFResource ** flatArray = new nsIRDFResource *[numElements];
|
||||
if (flatArray)
|
||||
{
|
||||
// flatten array of resources, sort them, then add as item elements
|
||||
unsigned long loop;
|
||||
|
||||
for (loop=0; loop<numElements; loop++)
|
||||
for (loop=0; loop<numElements; loop++)
|
||||
flatArray[loop] = (nsIRDFResource *)tempArray->ElementAt(loop);
|
||||
|
||||
if (nsnull != XULSortService)
|
||||
|
@ -570,26 +573,26 @@ RDFGenericBuilderImpl::CreateContents(nsIContent* aElement)
|
|||
XULSortService->OpenContainer(mDB, aElement, flatArray, numElements/2, 2*sizeof(nsIRDFResource *));
|
||||
}
|
||||
|
||||
for (loop=0; loop<numElements; loop+=2)
|
||||
{
|
||||
for (loop=0; loop<numElements; loop+=2)
|
||||
{
|
||||
if (NS_FAILED(rv = CreateWidgetItem(aElement, flatArray[loop+1], flatArray[loop], loop+1)))
|
||||
{
|
||||
NS_ERROR("unable to create widget item");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = numElements - 1; i >=0; i--)
|
||||
{
|
||||
for (int i = numElements - 1; i >=0; i--)
|
||||
{
|
||||
NS_IF_RELEASE(flatArray[i]);
|
||||
}
|
||||
}
|
||||
delete [] flatArray;
|
||||
}
|
||||
}
|
||||
for (int i = numElements - 1; i >= 0; i--)
|
||||
{
|
||||
tempArray->RemoveElementAt(i);
|
||||
}
|
||||
NS_IF_RELEASE(tempArray);
|
||||
}
|
||||
for (int i = numElements - 1; i >= 0; i--)
|
||||
{
|
||||
tempArray->RemoveElementAt(i);
|
||||
}
|
||||
NS_IF_RELEASE(tempArray);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -1053,7 +1056,10 @@ RDFGenericBuilderImpl::OnAssert(nsIRDFResource* aSubject,
|
|||
return rv;
|
||||
}
|
||||
|
||||
for (PRInt32 i = elements->Count() - 1; i >= 0; --i) {
|
||||
PRUint32 cnt = 0;
|
||||
rv = elements->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
for (PRInt32 i = cnt - 1; i >= 0; --i) {
|
||||
nsCOMPtr<nsIContent> element( do_QueryInterface(elements->ElementAt(i)) );
|
||||
|
||||
// XXX somehow figure out if building XUL kids on this
|
||||
|
@ -1137,7 +1143,10 @@ RDFGenericBuilderImpl::OnUnassert(nsIRDFResource* aSubject,
|
|||
return rv;
|
||||
}
|
||||
|
||||
for (PRInt32 i = elements->Count() - 1; i >= 0; --i) {
|
||||
PRUint32 cnt = 0;
|
||||
rv = elements->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
for (PRInt32 i = cnt - 1; i >= 0; --i) {
|
||||
nsCOMPtr<nsIContent> element( do_QueryInterface(elements->ElementAt(i)) );
|
||||
|
||||
// XXX somehow figure out if building XUL kids on this
|
||||
|
|
|
@ -169,7 +169,10 @@ nsresult nsClipboard::SetupNativeDataObject(nsITransferable * aTransferable, IDa
|
|||
// Walk through flavors that contain data and register them
|
||||
// into the DataObj as supported flavors
|
||||
PRUint32 i;
|
||||
for (i=0;i<dfList->Count();i++) {
|
||||
PRUint32 cnt = 0;
|
||||
nsresult rv = dfList->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
for (i=0;i<cnt;i++) {
|
||||
nsIDataFlavor * df;
|
||||
nsISupports * supports = dfList->ElementAt(i);
|
||||
if (NS_OK == supports->QueryInterface(kIDataFlavorIID, (void **)&df)) {
|
||||
|
@ -451,7 +454,10 @@ nsresult nsClipboard::GetDataFromDataObject(IDataObject * aDataObject,
|
|||
|
||||
// Walk through flavors and see which flavor is on the clipboard them on the native clipboard,
|
||||
PRUint32 i;
|
||||
for (i=0;i<dfList->Count();i++) {
|
||||
PRUint32 cnt = 0;
|
||||
nsresult rv = dfList->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
for (i=0;i<cnt;i++) {
|
||||
nsIDataFlavor * df;
|
||||
nsISupports * supports = dfList->ElementAt(i);
|
||||
if (NS_OK == supports->QueryInterface(kIDataFlavorIID, (void **)&df)) {
|
||||
|
@ -553,7 +559,10 @@ NS_IMETHODIMP nsClipboard::ForceDataToClipboard()
|
|||
|
||||
// Walk through flavors and see which flavor is on the native clipboard,
|
||||
PRUint32 i;
|
||||
for (i=0;i<dfList->Count();i++) {
|
||||
PRUint32 cnt = 0;
|
||||
nsresult rv = dfList->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
for (i=0;i<cnt;i++) {
|
||||
nsIDataFlavor * df;
|
||||
nsISupports * supports = dfList->ElementAt(i);
|
||||
if (NS_OK == supports->QueryInterface(kIDataFlavorIID, (void **)&df)) {
|
||||
|
|
|
@ -99,7 +99,11 @@ nsresult nsDragService::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
|||
//-------------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsDragService::InvokeDragSession (nsISupportsArray * anArrayTransferables, nsIRegion * aRegion, PRUint32 aActionType)
|
||||
{
|
||||
if (anArrayTransferables->Count() == 0) {
|
||||
nsresult rv;
|
||||
PRUint32 cnt;
|
||||
rv = anArrayTransferables->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (cnt == 0) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -108,7 +112,7 @@ NS_IMETHODIMP nsDragService::InvokeDragSession (nsISupportsArray * anArrayTransf
|
|||
|
||||
IDataObject * dataObj = nsnull;
|
||||
PRUint32 i;
|
||||
for (i=0;i<anArrayTransferables->Count();i++) {
|
||||
for (i=0;i<cnt;i++) {
|
||||
nsISupports * supports = anArrayTransferables->ElementAt(i);
|
||||
nsCOMPtr<nsITransferable> trans(do_QueryInterface(supports));
|
||||
NS_RELEASE(supports);
|
||||
|
|
|
@ -246,27 +246,35 @@ nsIWidget * nsMenu::GetParentWidget()
|
|||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenu::AddMenuItem(nsIMenuItem * aMenuItem)
|
||||
{
|
||||
return InsertItemAt(mItems->Count(), (nsISupports *)aMenuItem);
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mItems->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return InsertItemAt(cnt, (nsISupports *)aMenuItem);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenu::AddMenu(nsIMenu * aMenu)
|
||||
{
|
||||
return InsertItemAt(mItems->Count(), (nsISupports *)aMenu);
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mItems->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return InsertItemAt(cnt, (nsISupports *)aMenu);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenu::AddSeparator()
|
||||
{
|
||||
InsertSeparator(mItems->Count());
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mItems->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
InsertSeparator(cnt);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenu::GetItemCount(PRUint32 &aCount)
|
||||
{
|
||||
aCount = mItems->Count();
|
||||
return NS_OK;
|
||||
return mItems->Count(&aCount);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
@ -372,7 +380,12 @@ NS_METHOD nsMenu::RemoveItem(const PRUint32 aCount)
|
|||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenu::RemoveAll()
|
||||
{
|
||||
while (mItems->Count()) {
|
||||
while (PR_TRUE) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mItems->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (cnt == 0)
|
||||
break;
|
||||
mItems->RemoveElementAt(0);
|
||||
::RemoveMenu(mMenu, 0, MF_BYPOSITION);
|
||||
}
|
||||
|
@ -507,7 +520,12 @@ nsEventStatus nsMenu::MenuDestruct(const nsMenuEvent & aMenuEvent)
|
|||
// We cannot call RemoveAll() yet because menu item selection may need it
|
||||
//RemoveAll();
|
||||
|
||||
while (mItems->Count()) {
|
||||
while (PR_TRUE) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mItems->Count(&cnt);
|
||||
if (NS_FAILED(rv)) break; // XXX error?
|
||||
if (cnt == 0)
|
||||
break;
|
||||
mItems->RemoveElementAt(0);
|
||||
::RemoveMenu(mMenu, 0, MF_BYPOSITION);
|
||||
}
|
||||
|
|
|
@ -335,7 +335,10 @@ nsTransferable :: FlavorsTransferableCanImport ( nsISupportsArray** outFlavorLis
|
|||
converter->GetInputDataFlavors(getter_AddRefs(convertedList));
|
||||
if ( convertedList ) {
|
||||
PRUint32 i;
|
||||
for (i=0;i<convertedList->Count();i++) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = convertedList->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (i=0;i<cnt;i++) {
|
||||
nsCOMPtr<nsISupports> temp = getter_AddRefs(convertedList->ElementAt(i));
|
||||
(*outFlavorList)->AppendElement(temp); // this addref's for us
|
||||
} // foreach flavor that can be converted to
|
||||
|
@ -370,7 +373,10 @@ nsTransferable :: FlavorsTransferableCanExport ( nsISupportsArray** outFlavorLis
|
|||
converter->GetOutputDataFlavors(getter_AddRefs(convertedList));
|
||||
if ( convertedList ) {
|
||||
PRUint32 i;
|
||||
for (i=0;i<convertedList->Count();i++) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = convertedList->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
for (i=0;i<cnt;i++) {
|
||||
nsCOMPtr<nsISupports> temp = getter_AddRefs(convertedList->ElementAt(i));
|
||||
(*outFlavorList)->AppendElement(temp); // this addref's for us
|
||||
} // foreach flavor that can be converted to
|
||||
|
|
|
@ -41,7 +41,10 @@ nsArrayEnumerator::HasMoreElements(PRBool* aResult)
|
|||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aResult = (mIndex < (PRInt32) mValueArray->Count());
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mValueArray->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
*aResult = (mIndex < (PRInt32) cnt);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -52,7 +55,10 @@ nsArrayEnumerator::GetNext(nsISupports** aResult)
|
|||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (mIndex >= (PRInt32) mValueArray->Count())
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mValueArray->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (mIndex >= (PRInt32) cnt)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
*aResult = mValueArray->ElementAt(mIndex++);
|
||||
|
|
|
@ -1,80 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specifzic language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef nsICollection_h___
|
||||
#define nsICollection_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsIEnumerator;
|
||||
|
||||
// IID for the nsICollection interface
|
||||
#define NS_ICOLLECTION_IID \
|
||||
{ /* 83b6019c-cbc4-11d2-8cca-0060b0fc14a3 */ \
|
||||
0x83b6019c, \
|
||||
0xcbc4, \
|
||||
0x11d2, \
|
||||
{0x8c, 0xca, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
|
||||
}
|
||||
|
||||
// IID for the nsICollection Factory interface
|
||||
#define NS_ICOLLECTIONFACTORY_IID \
|
||||
{ 0xf8052641, 0x8768, 0x11d2, \
|
||||
{ 0x8f, 0x39, 0x0, 0x60, 0x8, 0x31, 0x1, 0x94 } }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
/** nsICollection Interface
|
||||
* this may be ordered or not. a list or array, the implementation is opaque
|
||||
*/
|
||||
class nsICollection : public nsISupports {
|
||||
public:
|
||||
|
||||
static const nsIID& GetIID(void) { static nsIID iid = NS_ICOLLECTION_IID; return iid; }
|
||||
|
||||
/** Return the count of elements in the collection.
|
||||
*/
|
||||
NS_IMETHOD_(PRUint32) Count(void) = 0;
|
||||
|
||||
/**
|
||||
* AppendElement will take an ISupports and keep track of it
|
||||
* @param aItem is the Item to be added WILL BE ADDREFFED
|
||||
* @return NS_OK if successfully added
|
||||
* @return NS_ERROR_FAILURE otherwise
|
||||
*/
|
||||
NS_IMETHOD AppendElement(nsISupports *aItem) = 0;
|
||||
|
||||
/** RemoveElement will take an nsISupports and remove it from the collection
|
||||
* @param aItem is the item to be removed WILL BE RELEASED
|
||||
* @return NS_OK if successfully added
|
||||
* @return NS_ERROR_FAILURE otherwise
|
||||
*/
|
||||
NS_IMETHOD RemoveElement(nsISupports *aItem) = 0;
|
||||
|
||||
/** Return an enumeration for the collection.
|
||||
*/
|
||||
NS_IMETHOD Enumerate(nsIEnumerator* *result) = 0;
|
||||
|
||||
/** Clear will clear all items from list
|
||||
*/
|
||||
NS_IMETHOD Clear(void) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* nsICollection_h___ */
|
||||
|
|
@ -56,7 +56,9 @@ nsISupportsArray::operator=(const nsISupportsArray& other)
|
|||
NS_IMETHODIMP_(nsISupportsArray&)
|
||||
nsSupportsArray::operator=(const nsISupportsArray& aOther)
|
||||
{
|
||||
PRUint32 otherCount = ((nsISupportsArray&)aOther).Count();
|
||||
PRUint32 otherCount = 0;
|
||||
nsresult rv = ((nsISupportsArray&)aOther).Count(&otherCount); // XXX bogus cast -- aOther should not be const
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "this method should return an error!");
|
||||
|
||||
if (otherCount > mArraySize) {
|
||||
DeleteArray();
|
||||
|
|
|
@ -31,7 +31,15 @@ public:
|
|||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsICollection methods:
|
||||
NS_IMETHOD_(PRUint32) Count(void) { return mCount; }
|
||||
NS_IMETHOD Count(PRUint32 *result) { *result = mCount; return NS_OK; }
|
||||
NS_IMETHOD GetElementAt(PRUint32 index, nsISupports* *result) {
|
||||
*result = ElementAt(index);
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD SetElementAt(PRUint32 index, nsISupports* value) {
|
||||
PRBool ok = ReplaceElementAt(value, index);
|
||||
return ok ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
NS_IMETHOD AppendElement(nsISupports *aElement) {
|
||||
// XXX This incorrectly returns a PRBool instead of an nsresult.
|
||||
return InsertElementAt(aElement, mCount);
|
||||
|
|
|
@ -55,7 +55,10 @@ NS_IMETHODIMP
|
|||
nsSupportsArrayEnumerator::First()
|
||||
{
|
||||
mCursor = 0;
|
||||
PRInt32 end = (PRInt32)mArray->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mArray->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
PRInt32 end = (PRInt32)cnt;
|
||||
if (mCursor < end)
|
||||
return NS_OK;
|
||||
else
|
||||
|
@ -65,7 +68,10 @@ nsSupportsArrayEnumerator::First()
|
|||
NS_IMETHODIMP
|
||||
nsSupportsArrayEnumerator::Next()
|
||||
{
|
||||
PRInt32 end = (PRInt32)mArray->Count();
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mArray->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
PRInt32 end = (PRInt32)cnt;
|
||||
if (mCursor < end) // don't count upward forever
|
||||
mCursor++;
|
||||
if (mCursor < end)
|
||||
|
@ -78,7 +84,10 @@ NS_IMETHODIMP
|
|||
nsSupportsArrayEnumerator::CurrentItem(nsISupports **aItem)
|
||||
{
|
||||
NS_ASSERTION(aItem, "null out parameter");
|
||||
if (mCursor >= 0 && mCursor < (PRInt32)mArray->Count()) {
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mArray->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (mCursor >= 0 && mCursor < (PRInt32)cnt) {
|
||||
*aItem = (*mArray)[mCursor];
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -88,7 +97,10 @@ nsSupportsArrayEnumerator::CurrentItem(nsISupports **aItem)
|
|||
NS_IMETHODIMP
|
||||
nsSupportsArrayEnumerator::IsDone()
|
||||
{
|
||||
return (mCursor >= 0 && mCursor < (PRInt32)mArray->Count())
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mArray->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return (mCursor >= 0 && mCursor < (PRInt32)cnt)
|
||||
? NS_COMFALSE : NS_OK;
|
||||
}
|
||||
|
||||
|
@ -97,7 +109,10 @@ nsSupportsArrayEnumerator::IsDone()
|
|||
NS_IMETHODIMP
|
||||
nsSupportsArrayEnumerator::Last()
|
||||
{
|
||||
mCursor = mArray->Count() - 1;
|
||||
PRUint32 cnt;
|
||||
nsresult rv = mArray->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
mCursor = cnt - 1;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,80 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specifzic language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef nsICollection_h___
|
||||
#define nsICollection_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsIEnumerator;
|
||||
|
||||
// IID for the nsICollection interface
|
||||
#define NS_ICOLLECTION_IID \
|
||||
{ /* 83b6019c-cbc4-11d2-8cca-0060b0fc14a3 */ \
|
||||
0x83b6019c, \
|
||||
0xcbc4, \
|
||||
0x11d2, \
|
||||
{0x8c, 0xca, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
|
||||
}
|
||||
|
||||
// IID for the nsICollection Factory interface
|
||||
#define NS_ICOLLECTIONFACTORY_IID \
|
||||
{ 0xf8052641, 0x8768, 0x11d2, \
|
||||
{ 0x8f, 0x39, 0x0, 0x60, 0x8, 0x31, 0x1, 0x94 } }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
/** nsICollection Interface
|
||||
* this may be ordered or not. a list or array, the implementation is opaque
|
||||
*/
|
||||
class nsICollection : public nsISupports {
|
||||
public:
|
||||
|
||||
static const nsIID& GetIID(void) { static nsIID iid = NS_ICOLLECTION_IID; return iid; }
|
||||
|
||||
/** Return the count of elements in the collection.
|
||||
*/
|
||||
NS_IMETHOD_(PRUint32) Count(void) = 0;
|
||||
|
||||
/**
|
||||
* AppendElement will take an ISupports and keep track of it
|
||||
* @param aItem is the Item to be added WILL BE ADDREFFED
|
||||
* @return NS_OK if successfully added
|
||||
* @return NS_ERROR_FAILURE otherwise
|
||||
*/
|
||||
NS_IMETHOD AppendElement(nsISupports *aItem) = 0;
|
||||
|
||||
/** RemoveElement will take an nsISupports and remove it from the collection
|
||||
* @param aItem is the item to be removed WILL BE RELEASED
|
||||
* @return NS_OK if successfully added
|
||||
* @return NS_ERROR_FAILURE otherwise
|
||||
*/
|
||||
NS_IMETHOD RemoveElement(nsISupports *aItem) = 0;
|
||||
|
||||
/** Return an enumeration for the collection.
|
||||
*/
|
||||
NS_IMETHOD Enumerate(nsIEnumerator* *result) = 0;
|
||||
|
||||
/** Clear will clear all items from list
|
||||
*/
|
||||
NS_IMETHOD Clear(void) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* nsICollection_h___ */
|
||||
|
|
@ -1,186 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsEnumeratorUtils.h"
|
||||
|
||||
|
||||
nsArrayEnumerator::nsArrayEnumerator(nsISupportsArray* aValueArray)
|
||||
: mValueArray(aValueArray),
|
||||
mIndex(0)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_IF_ADDREF(mValueArray);
|
||||
}
|
||||
|
||||
nsArrayEnumerator::~nsArrayEnumerator(void)
|
||||
{
|
||||
NS_IF_RELEASE(mValueArray);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsArrayEnumerator, nsISimpleEnumerator::GetIID());
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsArrayEnumerator::HasMoreElements(PRBool* aResult)
|
||||
{
|
||||
NS_PRECONDITION(aResult != 0, "null ptr");
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aResult = (mIndex < (PRInt32) mValueArray->Count());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsArrayEnumerator::GetNext(nsISupports** aResult)
|
||||
{
|
||||
NS_PRECONDITION(aResult != 0, "null ptr");
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (mIndex >= (PRInt32) mValueArray->Count())
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
*aResult = mValueArray->ElementAt(mIndex++);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsSingletonEnumerator::nsSingletonEnumerator(nsISupports* aValue)
|
||||
: mValue(aValue)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_IF_ADDREF(mValue);
|
||||
mConsumed = (mValue ? PR_FALSE : PR_TRUE);
|
||||
}
|
||||
|
||||
nsSingletonEnumerator::~nsSingletonEnumerator()
|
||||
{
|
||||
NS_IF_RELEASE(mValue);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsSingletonEnumerator, nsISimpleEnumerator::GetIID());
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSingletonEnumerator::HasMoreElements(PRBool* aResult)
|
||||
{
|
||||
NS_PRECONDITION(aResult != 0, "null ptr");
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aResult = !mConsumed;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSingletonEnumerator::GetNext(nsISupports** aResult)
|
||||
{
|
||||
NS_PRECONDITION(aResult != 0, "null ptr");
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (mConsumed)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
mConsumed = PR_TRUE;
|
||||
|
||||
NS_ADDREF(mValue);
|
||||
*aResult = mValue;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
nsAdapterEnumerator::nsAdapterEnumerator(nsIEnumerator* aEnum)
|
||||
: mEnum(aEnum), mCurrent(0), mStarted(PR_FALSE)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF(mEnum);
|
||||
}
|
||||
|
||||
|
||||
nsAdapterEnumerator::~nsAdapterEnumerator()
|
||||
{
|
||||
NS_RELEASE(mEnum);
|
||||
NS_IF_RELEASE(mCurrent);
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsAdapterEnumerator, nsISimpleEnumerator::GetIID());
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAdapterEnumerator::HasMoreElements(PRBool* aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
if (mCurrent) {
|
||||
*aResult = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (! mStarted) {
|
||||
mStarted = PR_TRUE;
|
||||
rv = mEnum->First();
|
||||
if (rv == NS_OK) {
|
||||
mEnum->CurrentItem(&mCurrent);
|
||||
*aResult = PR_TRUE;
|
||||
}
|
||||
else {
|
||||
*aResult = PR_FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
*aResult = PR_FALSE;
|
||||
|
||||
rv = mEnum->IsDone();
|
||||
if (rv != NS_OK) {
|
||||
// We're not done. Advance to the next one.
|
||||
rv = mEnum->Next();
|
||||
if (rv == NS_OK) {
|
||||
mEnum->CurrentItem(&mCurrent);
|
||||
*aResult = PR_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAdapterEnumerator::GetNext(nsISupports** aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
PRBool hasMore;
|
||||
rv = HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (! hasMore)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
// No need to addref, we "transfer" the ownership to the caller.
|
||||
*aResult = mCurrent;
|
||||
mCurrent = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
@ -1,359 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsSupportsArray.h"
|
||||
#include "nsSupportsArrayEnumerator.h"
|
||||
|
||||
static const PRUint32 kGrowArrayBy = 8;
|
||||
|
||||
nsSupportsArray::nsSupportsArray()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mArray = &(mAutoArray[0]);
|
||||
mArraySize = kAutoArraySize;
|
||||
mCount = 0;
|
||||
}
|
||||
|
||||
nsSupportsArray::~nsSupportsArray()
|
||||
{
|
||||
DeleteArray();
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsSupportsArray, nsISupportsArray::GetIID());
|
||||
|
||||
void nsSupportsArray::DeleteArray(void)
|
||||
{
|
||||
Clear();
|
||||
if (mArray != &(mAutoArray[0])) {
|
||||
delete[] mArray;
|
||||
mArray = &(mAutoArray[0]);
|
||||
mArraySize = kAutoArraySize;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsISupportsArray&)
|
||||
nsISupportsArray::operator=(const nsISupportsArray& other)
|
||||
{
|
||||
NS_ASSERTION(0, "should be an abstract method");
|
||||
return *this; // bogus
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsISupportsArray&)
|
||||
nsSupportsArray::operator=(const nsISupportsArray& aOther)
|
||||
{
|
||||
PRUint32 otherCount = ((nsISupportsArray&)aOther).Count();
|
||||
|
||||
if (otherCount > mArraySize) {
|
||||
DeleteArray();
|
||||
mArraySize = otherCount;
|
||||
mArray = new nsISupports*[mArraySize];
|
||||
}
|
||||
else {
|
||||
Clear();
|
||||
}
|
||||
mCount = otherCount;
|
||||
while (0 < otherCount--) {
|
||||
mArray[otherCount] = aOther.ElementAt(otherCount);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsSupportsArray::Equals(const nsISupportsArray* aOther) const
|
||||
{
|
||||
if (0 != aOther) {
|
||||
const nsSupportsArray* other = (const nsSupportsArray*)aOther;
|
||||
if (mCount == other->mCount) {
|
||||
PRUint32 index = mCount;
|
||||
while (0 < index--) {
|
||||
if (mArray[index] != other->mArray[index]) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsISupports*)
|
||||
nsSupportsArray::ElementAt(PRUint32 aIndex) const
|
||||
{
|
||||
if ((0 <= aIndex) && (aIndex < mCount)) {
|
||||
nsISupports* element = mArray[aIndex];
|
||||
NS_ADDREF(element);
|
||||
return element;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRInt32)
|
||||
nsSupportsArray::IndexOf(const nsISupports* aPossibleElement, PRUint32 aStartIndex) const
|
||||
{
|
||||
if ((0 <= aStartIndex) && (aStartIndex < mCount)) {
|
||||
const nsISupports** start = (const nsISupports**)mArray; // work around goofy compiler behavior
|
||||
const nsISupports** ep = (start + aStartIndex);
|
||||
const nsISupports** end = (start + mCount);
|
||||
while (ep < end) {
|
||||
if (aPossibleElement == *ep) {
|
||||
return (ep - start);
|
||||
}
|
||||
ep++;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRInt32)
|
||||
nsSupportsArray::LastIndexOf(const nsISupports* aPossibleElement) const
|
||||
{
|
||||
if (0 < mCount) {
|
||||
const nsISupports** start = (const nsISupports**)mArray; // work around goofy compiler behavior
|
||||
const nsISupports** ep = (start + mCount);
|
||||
while (start <= --ep) {
|
||||
if (aPossibleElement == *ep) {
|
||||
return (ep - start);
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsSupportsArray::InsertElementAt(nsISupports* aElement, PRUint32 aIndex)
|
||||
{
|
||||
if ((0 <= aIndex) && (aIndex <= mCount)) {
|
||||
if (mArraySize < (mCount + 1)) { // need to grow the array
|
||||
mArraySize += kGrowArrayBy;
|
||||
nsISupports** oldArray = mArray;
|
||||
mArray = new nsISupports*[mArraySize];
|
||||
if (0 == mArray) { // ran out of memory
|
||||
mArray = oldArray;
|
||||
mArraySize -= kGrowArrayBy;
|
||||
return PR_FALSE;
|
||||
}
|
||||
if (0 != oldArray) { // need to move old data
|
||||
if (0 < aIndex) {
|
||||
::memcpy(mArray, oldArray, aIndex * sizeof(nsISupports*));
|
||||
}
|
||||
PRUint32 slide = (mCount - aIndex);
|
||||
if (0 < slide) {
|
||||
::memcpy(mArray + aIndex + 1, oldArray + aIndex, slide * sizeof(nsISupports*));
|
||||
}
|
||||
if (oldArray != &(mAutoArray[0])) {
|
||||
delete[] oldArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
PRUint32 slide = (mCount - aIndex);
|
||||
if (0 < slide) {
|
||||
::memmove(mArray + aIndex + 1, mArray + aIndex, slide * sizeof(nsISupports*));
|
||||
}
|
||||
}
|
||||
|
||||
mArray[aIndex] = aElement;
|
||||
NS_ADDREF(aElement);
|
||||
mCount++;
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsSupportsArray::ReplaceElementAt(nsISupports* aElement, PRUint32 aIndex)
|
||||
{
|
||||
if ((0 <= aIndex) && (aIndex < mCount)) {
|
||||
NS_ADDREF(aElement); // addref first in case it's the same object!
|
||||
NS_RELEASE(mArray[aIndex]);
|
||||
mArray[aIndex] = aElement;
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsSupportsArray::RemoveElementAt(PRUint32 aIndex)
|
||||
{
|
||||
if ((0 <= aIndex) && (aIndex < mCount)) {
|
||||
NS_RELEASE(mArray[aIndex]);
|
||||
mCount--;
|
||||
PRInt32 slide = (mCount - aIndex);
|
||||
if (0 < slide) {
|
||||
::memmove(mArray + aIndex, mArray + aIndex + 1,
|
||||
slide * sizeof(nsISupports*));
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsSupportsArray::RemoveElement(const nsISupports* aElement, PRUint32 aStartIndex)
|
||||
{
|
||||
if ((0 <= aStartIndex) && (aStartIndex < mCount)) {
|
||||
nsISupports** ep = mArray;
|
||||
nsISupports** end = ep + mCount;
|
||||
while (ep < end) {
|
||||
if (*ep == aElement) {
|
||||
return RemoveElementAt(PRUint32(ep - mArray));
|
||||
}
|
||||
ep++;
|
||||
}
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsSupportsArray::RemoveLastElement(const nsISupports* aElement)
|
||||
{
|
||||
if (0 < mCount) {
|
||||
nsISupports** ep = (mArray + mCount);
|
||||
while (mArray <= --ep) {
|
||||
if (*ep == aElement) {
|
||||
return RemoveElementAt(PRUint32(ep - mArray));
|
||||
}
|
||||
}
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsSupportsArray::AppendElements(nsISupportsArray* aElements)
|
||||
{
|
||||
nsSupportsArray* elements = (nsSupportsArray*)aElements;
|
||||
|
||||
if (elements && (0 < elements->mCount)) {
|
||||
if (mArraySize < (mCount + elements->mCount)) { // need to grow the array
|
||||
PRUint32 count = mCount + elements->mCount;
|
||||
PRUint32 oldSize = mArraySize;
|
||||
while (mArraySize < count) { // ick
|
||||
mArraySize += kGrowArrayBy;
|
||||
}
|
||||
nsISupports** oldArray = mArray;
|
||||
mArray = new nsISupports*[mArraySize];
|
||||
if (0 == mArray) { // ran out of memory
|
||||
mArray = oldArray;
|
||||
mArraySize = oldSize;
|
||||
return PR_FALSE;
|
||||
}
|
||||
if (0 != oldArray) { // need to move old data
|
||||
if (0 < mCount) {
|
||||
::memcpy(mArray, oldArray, mCount);
|
||||
}
|
||||
if (oldArray != &(mAutoArray[0])) {
|
||||
delete[] oldArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PRUint32 index = 0;
|
||||
while (index < elements->mCount) {
|
||||
NS_ADDREF(elements->mArray[index]);
|
||||
mArray[mCount++] = elements->mArray[index++];
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSupportsArray::Clear(void)
|
||||
{
|
||||
if (0 < mCount) {
|
||||
do {
|
||||
--mCount;
|
||||
NS_RELEASE(mArray[mCount]);
|
||||
} while (0 != mCount);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(void)
|
||||
nsSupportsArray::Compact(void)
|
||||
{
|
||||
if ((mArraySize != mCount) && (kAutoArraySize < mArraySize)) {
|
||||
nsISupports** oldArray = mArray;
|
||||
PRUint32 oldArraySize = mArraySize;
|
||||
if (mCount <= kAutoArraySize) {
|
||||
mArray = &(mAutoArray[0]);
|
||||
mArraySize = kAutoArraySize;
|
||||
}
|
||||
else {
|
||||
mArray = new nsISupports*[mCount];
|
||||
mArraySize = mCount;
|
||||
}
|
||||
if (0 == mArray) {
|
||||
mArray = oldArray;
|
||||
mArraySize = oldArraySize;
|
||||
return;
|
||||
}
|
||||
::memcpy(mArray, oldArray, mCount * sizeof(nsISupports*));
|
||||
delete[] oldArray;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsSupportsArray::EnumerateForwards(nsISupportsArrayEnumFunc aFunc, void* aData) const
|
||||
{
|
||||
PRInt32 index = -1;
|
||||
PRBool running = PR_TRUE;
|
||||
|
||||
while (running && (++index < (PRInt32)mCount)) {
|
||||
running = (*aFunc)(mArray[index], aData);
|
||||
}
|
||||
return running;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsSupportsArray::EnumerateBackwards(nsISupportsArrayEnumFunc aFunc, void* aData) const
|
||||
{
|
||||
PRUint32 index = mCount;
|
||||
PRBool running = PR_TRUE;
|
||||
|
||||
while (running && (0 < index--)) {
|
||||
running = (*aFunc)(mArray[index], aData);
|
||||
}
|
||||
return running;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSupportsArray::Enumerate(nsIEnumerator* *result)
|
||||
{
|
||||
nsSupportsArrayEnumerator* e = new nsSupportsArrayEnumerator(this);
|
||||
if (!e)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
*result = e;
|
||||
NS_ADDREF(e);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_COM nsresult
|
||||
NS_NewISupportsArray(nsISupportsArray** aInstancePtrResult)
|
||||
{
|
||||
if (aInstancePtrResult == 0)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsSupportsArray *it = new nsSupportsArray();
|
||||
if (0 == it)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(it);
|
||||
*aInstancePtrResult = it;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -1,85 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsSupportsArray_h__
|
||||
#define nsSupportsArray_h__
|
||||
|
||||
#include "nsISupportsArray.h"
|
||||
|
||||
static const PRUint32 kAutoArraySize = 4;
|
||||
|
||||
class nsSupportsArray : public nsISupportsArray {
|
||||
public:
|
||||
nsSupportsArray(void);
|
||||
virtual ~nsSupportsArray(void);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsICollection methods:
|
||||
NS_IMETHOD_(PRUint32) Count(void) { return mCount; }
|
||||
NS_IMETHOD AppendElement(nsISupports *aElement) {
|
||||
// XXX This incorrectly returns a PRBool instead of an nsresult.
|
||||
return InsertElementAt(aElement, mCount);
|
||||
}
|
||||
NS_IMETHOD RemoveElement(nsISupports *aElement) {
|
||||
// XXX This incorrectly returns a PRBool instead of an nsresult.
|
||||
return RemoveElement(aElement, 0);
|
||||
}
|
||||
NS_IMETHOD Enumerate(nsIEnumerator* *result);
|
||||
NS_IMETHOD Clear(void);
|
||||
|
||||
// nsISupportsArray methods:
|
||||
NS_IMETHOD_(nsISupportsArray&) operator=(const nsISupportsArray& aOther);
|
||||
NS_IMETHOD_(PRBool) operator==(const nsISupportsArray& aOther) const { return Equals(&aOther); }
|
||||
NS_IMETHOD_(PRBool) Equals(const nsISupportsArray* aOther) const;
|
||||
|
||||
NS_IMETHOD_(nsISupports*) ElementAt(PRUint32 aIndex) const;
|
||||
NS_IMETHOD_(nsISupports*) operator[](PRUint32 aIndex) const { return ElementAt(aIndex); }
|
||||
|
||||
NS_IMETHOD_(PRInt32) IndexOf(const nsISupports* aPossibleElement, PRUint32 aStartIndex = 0) const;
|
||||
NS_IMETHOD_(PRInt32) LastIndexOf(const nsISupports* aPossibleElement) const;
|
||||
|
||||
NS_IMETHOD_(PRBool) InsertElementAt(nsISupports* aElement, PRUint32 aIndex);
|
||||
|
||||
NS_IMETHOD_(PRBool) ReplaceElementAt(nsISupports* aElement, PRUint32 aIndex);
|
||||
|
||||
NS_IMETHOD_(PRBool) RemoveElementAt(PRUint32 aIndex);
|
||||
NS_IMETHOD_(PRBool) RemoveElement(const nsISupports* aElement, PRUint32 aStartIndex = 0);
|
||||
NS_IMETHOD_(PRBool) RemoveLastElement(const nsISupports* aElement);
|
||||
|
||||
NS_IMETHOD_(PRBool) AppendElements(nsISupportsArray* aElements);
|
||||
|
||||
NS_IMETHOD_(void) Compact(void);
|
||||
|
||||
NS_IMETHOD_(PRBool) EnumerateForwards(nsISupportsArrayEnumFunc aFunc, void* aData) const;
|
||||
NS_IMETHOD_(PRBool) EnumerateBackwards(nsISupportsArrayEnumFunc aFunc, void* aData) const;
|
||||
|
||||
protected:
|
||||
void DeleteArray(void);
|
||||
|
||||
nsISupports** mArray;
|
||||
PRUint32 mArraySize;
|
||||
PRUint32 mCount;
|
||||
nsISupports* mAutoArray[kAutoArraySize];
|
||||
|
||||
private:
|
||||
// Copy constructors are not allowed
|
||||
nsSupportsArray(const nsISupportsArray& other);
|
||||
};
|
||||
|
||||
#endif // nsSupportsArray_h__
|
|
@ -1,132 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsSupportsArrayEnumerator.h"
|
||||
#include "nsISupportsArray.h"
|
||||
|
||||
nsSupportsArrayEnumerator::nsSupportsArrayEnumerator(nsISupportsArray* array)
|
||||
: mArray(array), mCursor(0)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ASSERTION(array, "null array");
|
||||
NS_ADDREF(mArray);
|
||||
}
|
||||
|
||||
nsSupportsArrayEnumerator::~nsSupportsArrayEnumerator()
|
||||
{
|
||||
NS_RELEASE(mArray);
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsSupportsArrayEnumerator);
|
||||
NS_IMPL_RELEASE(nsSupportsArrayEnumerator);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSupportsArrayEnumerator::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aIID.Equals(nsIBidirectionalEnumerator::GetIID()) ||
|
||||
aIID.Equals(nsIEnumerator::GetIID()) ||
|
||||
aIID.Equals(nsISupports::GetIID())) {
|
||||
*aInstancePtr = (void*) this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSupportsArrayEnumerator::First()
|
||||
{
|
||||
mCursor = 0;
|
||||
PRInt32 end = (PRInt32)mArray->Count();
|
||||
if (mCursor < end)
|
||||
return NS_OK;
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSupportsArrayEnumerator::Next()
|
||||
{
|
||||
PRInt32 end = (PRInt32)mArray->Count();
|
||||
if (mCursor < end) // don't count upward forever
|
||||
mCursor++;
|
||||
if (mCursor < end)
|
||||
return NS_OK;
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSupportsArrayEnumerator::CurrentItem(nsISupports **aItem)
|
||||
{
|
||||
NS_ASSERTION(aItem, "null out parameter");
|
||||
if (mCursor >= 0 && mCursor < (PRInt32)mArray->Count()) {
|
||||
*aItem = (*mArray)[mCursor];
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSupportsArrayEnumerator::IsDone()
|
||||
{
|
||||
return (mCursor >= 0 && mCursor < (PRInt32)mArray->Count())
|
||||
? NS_COMFALSE : NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSupportsArrayEnumerator::Last()
|
||||
{
|
||||
mCursor = mArray->Count() - 1;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSupportsArrayEnumerator::Prev()
|
||||
{
|
||||
if (mCursor >= 0)
|
||||
--mCursor;
|
||||
if (mCursor >= 0)
|
||||
return NS_OK;
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_COM nsresult
|
||||
NS_NewISupportsArrayEnumerator(nsISupportsArray* array,
|
||||
nsIBidirectionalEnumerator* *aInstancePtrResult)
|
||||
{
|
||||
if (aInstancePtrResult == 0)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
nsSupportsArrayEnumerator* e = new nsSupportsArrayEnumerator(array);
|
||||
if (e == 0)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(e);
|
||||
*aInstancePtrResult = e;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -74,7 +74,10 @@ const char* AssertEqual(PRInt32 aValue1, PRInt32 aValue2)
|
|||
|
||||
void DumpArray(nsISupportsArray* aArray, PRInt32 aExpectedCount, PRInt32 aElementIDs[], PRInt32 aExpectedTotal)
|
||||
{
|
||||
PRInt32 count = aArray->Count();
|
||||
PRUint32 cnt = 0;
|
||||
nsresult rv = aArray->Count(&cnt);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
PRInt32 count = cnt;
|
||||
PRInt32 index;
|
||||
|
||||
fprintf(stdout, "object count %d = %d %s\n", IFoo::gCount, aExpectedTotal,
|
||||
|
|
|
@ -335,7 +335,12 @@ nsThreadPool::GetRequest()
|
|||
|
||||
PR_EnterMonitor(mRequestMonitor);
|
||||
|
||||
while (mRequests->Count() == 0) {
|
||||
PRUint32 cnt;
|
||||
while (PR_TRUE) {
|
||||
rv = mRequests->Count(&cnt);
|
||||
if (NS_FAILED(rv) || cnt != 0)
|
||||
break;
|
||||
|
||||
if (mShuttingDown) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
break;
|
||||
|
@ -349,7 +354,8 @@ nsThreadPool::GetRequest()
|
|||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
NS_ASSERTION(mRequests->Count() > 0, "request queue out of sync");
|
||||
NS_ASSERTION((NS_SUCCEEDED(mRequests->Count(&cnt)) && cnt > 0),
|
||||
"request queue out of sync");
|
||||
request = (nsIRunnable*)(*mRequests)[0];
|
||||
NS_ASSERTION(request != nsnull, "null runnable");
|
||||
|
||||
|
@ -366,7 +372,12 @@ nsThreadPool::ProcessPendingRequests()
|
|||
nsresult rv;
|
||||
PR_CEnterMonitor(this);
|
||||
|
||||
while (mRequests->Count() > 0) {
|
||||
while (PR_TRUE) {
|
||||
PRUint32 cnt;
|
||||
rv = mRequests->Count(&cnt);
|
||||
if (NS_FAILED(rv) || cnt == 0)
|
||||
break;
|
||||
|
||||
PRStatus status = PR_CWait(this, PR_INTERVAL_NO_TIMEOUT);
|
||||
if (status != PR_SUCCESS) {
|
||||
rv = NS_ERROR_FAILURE; // our thread was interrupted!
|
||||
|
@ -382,14 +393,15 @@ NS_IMETHODIMP
|
|||
nsThreadPool::Shutdown()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
PRUint32 count;
|
||||
PRUint32 count = 0;
|
||||
PRUint32 i;
|
||||
|
||||
mShuttingDown = PR_TRUE;
|
||||
ProcessPendingRequests();
|
||||
|
||||
// then interrupt the threads and join them
|
||||
count = mThreads->Count();
|
||||
rv = mThreads->Count(&count);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||
for (i = 0; i < count; i++) {
|
||||
nsIThread* thread = (nsIThread*)((*mThreads)[0]);
|
||||
|
||||
|
|
|
@ -411,7 +411,10 @@ nsAppShellService::UnregisterTopLevelWindow(nsIWebShellWindow* aWindow)
|
|||
mWindowList->RemoveElement(wsc);
|
||||
NS_RELEASE(wsc);
|
||||
}
|
||||
if (0 == mWindowList->Count())
|
||||
PRUint32 cnt;
|
||||
rv = mWindowList->Count(&cnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (0 == cnt)
|
||||
mAppShell->Exit();
|
||||
return rv;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче