bug 808229 - inline the one use of the 2 arg runnable r=surkov

This commit is contained in:
Trevor Saunders 2012-11-02 18:06:27 -04:00
Родитель f21a05277c
Коммит 242ecb43dd
3 изменённых файлов: 28 добавлений и 72 удалений

Просмотреть файл

@ -31,71 +31,4 @@
return ret; \
PR_END_MACRO
////////////////////////////////////////////////////////////////////////////////
// nsRunnable helpers
////////////////////////////////////////////////////////////////////////////////
/**
* Use NS_DECL_RUNNABLEMETHOD_ macros to declare a runnable class for the given
* method of the given class. There are three macros:
* NS_DECL_RUNNABLEMETHOD(Class, Method)
* NS_DECL_RUNNABLEMETHOD_ARG1(Class, Method, Arg1Type)
* NS_DECL_RUNNABLEMETHOD_ARG2(Class, Method, Arg1Type, Arg2Type)
* Note Arg1Type and Arg2Type must be types which keeps the objects alive.
*
* Use NS_DISPATCH_RUNNABLEMETHOD_ macros to create an instance of declared
* runnable class and dispatch it to main thread. Availabe macros are:
* NS_DISPATCH_RUNNABLEMETHOD(Method, Object)
* NS_DISPATCH_RUNNABLEMETHOD_ARG1(Method, Object, Arg1)
* NS_DISPATCH_RUNNABLEMETHOD_ARG2(Method, Object, Arg1, Arg2)
*/
#define NS_DECL_RUNNABLEMETHOD_HELPER(ClassType, Method) \
void Revoke() \
{ \
NS_IF_RELEASE(mObj); \
} \
\
protected: \
virtual ~nsRunnableMethod_##Method() \
{ \
NS_IF_RELEASE(mObj); \
} \
\
private: \
ClassType *mObj; \
#define NS_DECL_RUNNABLEMETHOD_ARG2(ClassType, Method, Arg1Type, Arg2Type) \
class nsRunnableMethod_##Method : public nsRunnable \
{ \
public: \
\
nsRunnableMethod_##Method(ClassType *aObj, \
Arg1Type aArg1, Arg2Type aArg2) : \
mObj(aObj), mArg1(aArg1), mArg2(aArg2) \
{ \
NS_IF_ADDREF(mObj); \
} \
\
NS_IMETHODIMP Run() \
{ \
if (!mObj) \
return NS_OK; \
(mObj-> Method)(mArg1, mArg2); \
return NS_OK; \
} \
\
NS_DECL_RUNNABLEMETHOD_HELPER(ClassType, Method) \
Arg1Type mArg1; \
Arg2Type mArg2; \
};
#define NS_DISPATCH_RUNNABLEMETHOD_ARG2(Method, Obj, Arg1, Arg2) \
{ \
nsCOMPtr<nsIRunnable> runnable = \
new nsRunnableMethod_##Method(Obj, Arg1, Arg2); \
if (runnable) \
NS_DispatchToMainThread(runnable); \
}
#endif

Просмотреть файл

@ -2105,9 +2105,35 @@ NS_IMETHODIMP Accessible::GetNativeInterface(void **aOutAccessible)
void
Accessible::DoCommand(nsIContent *aContent, uint32_t aActionIndex)
{
class Runnable MOZ_FINAL : public nsRunnable
{
public:
Runnable(Accessible* aAcc, nsIContent* aContent, uint32_t aIdx) :
mAcc(aAcc), mContent(aContent), mIdx(aIdx) { }
NS_IMETHOD Run()
{
if (mAcc)
mAcc->DispatchClickEvent(mContent, mIdx);
return NS_OK;
}
void Revoke()
{
mAcc = nullptr;
mContent = nullptr;
}
private:
nsRefPtr<Accessible> mAcc;
nsCOMPtr<nsIContent> mContent;
uint32_t mIdx;
};
nsIContent* content = aContent ? aContent : mContent.get();
NS_DISPATCH_RUNNABLEMETHOD_ARG2(DispatchClickEvent, this, content,
aActionIndex);
nsCOMPtr<nsIRunnable> runnable = new Runnable(this, content, aActionIndex);
NS_DispatchToMainThread(runnable);
}
void

Просмотреть файл

@ -859,9 +859,6 @@ protected:
*/
virtual void DispatchClickEvent(nsIContent *aContent, uint32_t aActionIndex);
NS_DECL_RUNNABLEMETHOD_ARG2(Accessible, DispatchClickEvent,
nsCOMPtr<nsIContent>, uint32_t)
//////////////////////////////////////////////////////////////////////////////
// Helpers