Bug 851134 - Part b: Implement the EventTarget getters in the WebIDL API for Event directly instead of calling the XPIDL implementations; r=smaug

This commit is contained in:
Ms2ger 2013-03-17 08:55:17 +01:00
Родитель 9d5daf95e9
Коммит 55b04bd76f
6 изменённых файлов: 65 добавлений и 65 удалений

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

@ -36,6 +36,7 @@
#include "nsPIWindowRoot.h"
using namespace mozilla;
using namespace mozilla::dom;
static char *sPopupAllowedEvents;
@ -92,7 +93,7 @@ nsDOMEvent::InitPresContextData(nsPresContext* aPresContext)
// Get the explicit original target (if it's anonymous make it null)
{
nsCOMPtr<nsIContent> content = GetTargetFromFrame();
mExplicitOriginalTarget = do_QueryInterface(content);
mExplicitOriginalTarget = content;
if (content && content->IsInAnonymousSubtree()) {
mExplicitOriginalTarget = nullptr;
}
@ -222,28 +223,36 @@ NS_METHOD nsDOMEvent::GetType(nsAString& aType)
return NS_OK;
}
static nsresult
GetDOMEventTarget(nsIDOMEventTarget* aTarget,
nsIDOMEventTarget** aDOMTarget)
static EventTarget*
GetDOMEventTarget(nsIDOMEventTarget* aTarget)
{
nsIDOMEventTarget* realTarget =
aTarget ? aTarget->GetTargetForDOMEvent() : aTarget;
return aTarget ? aTarget->GetTargetForDOMEvent() : nullptr;
}
NS_IF_ADDREF(*aDOMTarget = realTarget);
return NS_OK;
EventTarget*
nsDOMEvent::GetTarget() const
{
return GetDOMEventTarget(mEvent->target);
}
NS_METHOD
nsDOMEvent::GetTarget(nsIDOMEventTarget** aTarget)
{
return GetDOMEventTarget(mEvent->target, aTarget);
NS_IF_ADDREF(*aTarget = GetTarget());
return NS_OK;
}
EventTarget*
nsDOMEvent::GetCurrentTarget() const
{
return GetDOMEventTarget(mEvent->currentTarget);
}
NS_IMETHODIMP
nsDOMEvent::GetCurrentTarget(nsIDOMEventTarget** aCurrentTarget)
{
return GetDOMEventTarget(mEvent->currentTarget, aCurrentTarget);
NS_IF_ADDREF(*aCurrentTarget = GetCurrentTarget());
return NS_OK;
}
//
@ -264,26 +273,37 @@ nsDOMEvent::GetTargetFromFrame()
return realEventContent.forget();
}
EventTarget*
nsDOMEvent::GetExplicitOriginalTarget() const
{
if (mExplicitOriginalTarget) {
return mExplicitOriginalTarget;
}
return GetTarget();
}
NS_IMETHODIMP
nsDOMEvent::GetExplicitOriginalTarget(nsIDOMEventTarget** aRealEventTarget)
{
if (mExplicitOriginalTarget) {
*aRealEventTarget = mExplicitOriginalTarget;
NS_ADDREF(*aRealEventTarget);
return NS_OK;
NS_IF_ADDREF(*aRealEventTarget = GetExplicitOriginalTarget());
return NS_OK;
}
EventTarget*
nsDOMEvent::GetOriginalTarget() const
{
if (mEvent->originalTarget) {
return GetDOMEventTarget(mEvent->originalTarget);
}
return GetTarget(aRealEventTarget);
return GetTarget();
}
NS_IMETHODIMP
nsDOMEvent::GetOriginalTarget(nsIDOMEventTarget** aOriginalTarget)
{
if (mEvent->originalTarget) {
return GetDOMEventTarget(mEvent->originalTarget, aOriginalTarget);
}
return GetTarget(aOriginalTarget);
NS_IF_ADDREF(*aOriginalTarget = GetOriginalTarget());
return NS_OK;
}
NS_IMETHODIMP_(void)

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

@ -126,21 +126,8 @@ public:
// Implemented as xpidl method
// void GetType(nsString& aRetval) {}
already_AddRefed<mozilla::dom::EventTarget> GetTarget()
{
nsCOMPtr<nsIDOMEventTarget> t;
GetTarget(getter_AddRefs(t));
nsCOMPtr<mozilla::dom::EventTarget> et = do_QueryInterface(t);
return et.forget();
}
already_AddRefed<mozilla::dom::EventTarget> GetCurrentTarget()
{
nsCOMPtr<nsIDOMEventTarget> t;
GetCurrentTarget(getter_AddRefs(t));
nsCOMPtr<mozilla::dom::EventTarget> et = do_QueryInterface(t);
return et.forget();
}
mozilla::dom::EventTarget* GetTarget() const;
mozilla::dom::EventTarget* GetCurrentTarget() const;
uint16_t EventPhase() const;
@ -189,21 +176,8 @@ public:
aRv = InitEvent(aType, aBubbles, aCancelable);
}
already_AddRefed<mozilla::dom::EventTarget> GetOriginalTarget()
{
nsCOMPtr<nsIDOMEventTarget> t;
GetOriginalTarget(getter_AddRefs(t));
nsCOMPtr<mozilla::dom::EventTarget> et = do_QueryInterface(t);
return et.forget();
}
already_AddRefed<mozilla::dom::EventTarget> GetExplicitOriginalTarget()
{
nsCOMPtr<nsIDOMEventTarget> t;
GetExplicitOriginalTarget(getter_AddRefs(t));
nsCOMPtr<mozilla::dom::EventTarget> et = do_QueryInterface(t);
return et.forget();
}
mozilla::dom::EventTarget* GetOriginalTarget() const;
mozilla::dom::EventTarget* GetExplicitOriginalTarget() const;
bool GetPreventDefault() const
{
@ -218,7 +192,7 @@ protected:
nsEvent* mEvent;
nsRefPtr<nsPresContext> mPresContext;
nsCOMPtr<nsIDOMEventTarget> mExplicitOriginalTarget;
nsCOMPtr<mozilla::dom::EventTarget> mExplicitOriginalTarget;
nsCOMPtr<nsPIDOMWindow> mOwner; // nsPIDOMWindow for now.
nsString mCachedType;
bool mEventIsInternal;

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

@ -178,10 +178,10 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsDOMEventTargetHelper,
NS_IMETHOD DispatchEvent(nsIDOMEvent *evt, bool *_retval) { \
return _to DispatchEvent(evt, _retval); \
} \
virtual nsIDOMEventTarget * GetTargetForDOMEvent(void) { \
virtual mozilla::dom::EventTarget* GetTargetForDOMEvent() { \
return _to GetTargetForDOMEvent(); \
} \
virtual nsIDOMEventTarget * GetTargetForEventTargetChain(void) { \
virtual mozilla::dom::EventTarget* GetTargetForEventTargetChain() { \
return _to GetTargetForEventTargetChain(); \
} \
virtual nsresult WillHandleEvent(nsEventChainPostVisitor & aVisitor) { \

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

@ -2668,17 +2668,16 @@ nsGlobalWindow::GetIsTabModalPromptAllowed()
return allowTabModal;
}
nsIDOMEventTarget*
EventTarget*
nsGlobalWindow::GetTargetForDOMEvent()
{
return static_cast<nsIDOMEventTarget*>(GetOuterWindowInternal());
return GetOuterWindowInternal();
}
nsIDOMEventTarget*
EventTarget*
nsGlobalWindow::GetTargetForEventTargetChain()
{
return IsInnerWindow() ?
this : static_cast<nsIDOMEventTarget*>(GetCurrentInnerWindowInternal());
return IsInnerWindow() ? this : GetCurrentInnerWindowInternal();
}
nsresult

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

@ -2441,13 +2441,13 @@ nsDOMDeviceStorage::DispatchEvent(nsIDOMEvent *aEvt,
return nsDOMEventTargetHelper::DispatchEvent(aEvt, aRetval);
}
nsIDOMEventTarget *
EventTarget*
nsDOMDeviceStorage::GetTargetForDOMEvent()
{
return nsDOMEventTargetHelper::GetTargetForDOMEvent();
}
nsIDOMEventTarget *
EventTarget *
nsDOMDeviceStorage::GetTargetForEventTargetChain()
{
return nsDOMEventTargetHelper::GetTargetForEventTargetChain();

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

@ -11,6 +11,12 @@
using mozilla::dom::Nullable;
namespace mozilla {
namespace dom {
class EventTarget;
} // namespace dom
} // namespace mozilla
class nsPresContext;
class nsEventChainPreVisitor;
class nsEventChainPostVisitor;
@ -33,6 +39,7 @@ class nsEventListenerManager;
[ptr] native nsEventStatusPtr(nsEventStatus);
[ptr] native JSContextPtr(JSContext);
[ptr] native nsEventListenerManagerPtr(nsEventListenerManager);
[ptr] native EventTargetPtr(mozilla::dom::EventTarget);
interface nsIScriptContext;
interface nsIDOMEventListener;
@ -191,7 +198,7 @@ interface nsIDOMEventTarget : nsISupports
* Usually |this| is returned, but for example global object returns
* the outer object.
*/
[notxpcom, nostdcall] nsIDOMEventTarget GetTargetForDOMEvent();
[notxpcom, nostdcall] EventTargetPtr GetTargetForDOMEvent();
/**
* Returns the nsIDOMEventTarget object which should be used as the target
@ -199,7 +206,7 @@ interface nsIDOMEventTarget : nsISupports
* Usually |this| is returned, but for example global object returns
* the inner object.
*/
[notxpcom, nostdcall] nsIDOMEventTarget GetTargetForEventTargetChain();
[notxpcom, nostdcall] EventTargetPtr GetTargetForEventTargetChain();
/**
* Called before the capture phase of the event flow.
@ -287,8 +294,8 @@ interface nsIDOMEventTarget : nsISupports
%{C++
#define NS_IMPL_DOMTARGET_DEFAULTS(_class) \
nsIDOMEventTarget* _class::GetTargetForDOMEvent() { return this; } \
nsIDOMEventTarget* _class::GetTargetForEventTargetChain() { return this; } \
mozilla::dom::EventTarget* _class::GetTargetForDOMEvent() { return this; } \
mozilla::dom::EventTarget* _class::GetTargetForEventTargetChain() { return this; } \
nsresult _class::WillHandleEvent(nsEventChainPostVisitor& aVisitor) { return NS_OK; } \
JSContext* _class::GetJSContextForEventHandlers() { return nullptr; }