Bug 786048: Rename 'JSEventListener' to 'EventHandler' to better match the spec's terminology. r=smaug

This commit is contained in:
Kyle Huey 2012-08-30 09:25:10 -07:00
Родитель d9251c042c
Коммит 20210893cb
9 изменённых файлов: 72 добавлений и 71 удалений

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

@ -1809,9 +1809,9 @@ nsGenericElement::LeaveLink(nsPresContext* aPresContext)
} }
nsresult nsresult
nsGenericElement::AddScriptEventListener(nsIAtom* aEventName, nsGenericElement::SetEventHandler(nsIAtom* aEventName,
const nsAString& aValue, const nsAString& aValue,
bool aDefer) bool aDefer)
{ {
nsIDocument *ownerDoc = OwnerDoc(); nsIDocument *ownerDoc = OwnerDoc();
if (ownerDoc->IsLoadedAsData()) { if (ownerDoc->IsLoadedAsData()) {
@ -1829,8 +1829,9 @@ nsGenericElement::AddScriptEventListener(nsIAtom* aEventName,
} }
defer = defer && aDefer; // only defer if everyone agrees... defer = defer && aDefer; // only defer if everyone agrees...
manager->AddScriptEventListener(aEventName, aValue, nsIProgrammingLanguage::JAVASCRIPT, manager->SetEventHandler(aEventName, aValue,
defer, !nsContentUtils::IsChromeDoc(ownerDoc)); nsIProgrammingLanguage::JAVASCRIPT,
defer, !nsContentUtils::IsChromeDoc(ownerDoc));
return NS_OK; return NS_OK;
} }

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

@ -210,9 +210,9 @@ public:
* @param aValue the JS to attach * @param aValue the JS to attach
* @param aDefer indicates if deferred execution is allowed * @param aDefer indicates if deferred execution is allowed
*/ */
nsresult AddScriptEventListener(nsIAtom* aEventName, nsresult SetEventHandler(nsIAtom* aEventName,
const nsAString& aValue, const nsAString& aValue,
bool aDefer = true); bool aDefer = true);
/** /**
* Do whatever needs to be done when the mouse leaves a link * Do whatever needs to be done when the mouse leaves a link

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

@ -1964,16 +1964,16 @@ nsINode::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
#define EVENT(name_, id_, type_, struct_) \ #define EVENT(name_, id_, type_, struct_) \
NS_IMETHODIMP nsINode::GetOn##name_(JSContext *cx, jsval *vp) { \ NS_IMETHODIMP nsINode::GetOn##name_(JSContext *cx, jsval *vp) { \
nsEventListenerManager *elm = GetListenerManager(false); \ nsEventListenerManager *elm = GetListenerManager(false); \
if (elm) { \ if (elm) { \
elm->GetJSEventListener(nsGkAtoms::on##name_, vp); \ elm->GetEventHandler(nsGkAtoms::on##name_, vp); \
} else { \ } else { \
*vp = JSVAL_NULL; \ *vp = JSVAL_NULL; \
} \ } \
return NS_OK; \ return NS_OK; \
} \ } \
NS_IMETHODIMP nsINode::SetOn##name_(JSContext *cx, const jsval &v) { \ NS_IMETHODIMP nsINode::SetOn##name_(JSContext *cx, const jsval &v) { \
nsEventListenerManager *elm = GetListenerManager(true); \ nsEventListenerManager *elm = GetListenerManager(true); \
if (!elm) { \ if (!elm) { \
return NS_ERROR_OUT_OF_MEMORY; \ return NS_ERROR_OUT_OF_MEMORY; \
} \ } \
@ -1983,7 +1983,7 @@ nsINode::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
/* Just silently do nothing */ \ /* Just silently do nothing */ \
return NS_OK; \ return NS_OK; \
} \ } \
return elm->SetJSEventListenerToJsval(nsGkAtoms::on##name_, cx, obj, v); \ return elm->SetEventHandlerToJsval(nsGkAtoms::on##name_, cx, obj, v); \
} }
#define TOUCH_EVENT EVENT #define TOUCH_EVENT EVENT
#define DOCUMENT_ONLY_EVENT EVENT #define DOCUMENT_ONLY_EVENT EVENT

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

@ -455,8 +455,8 @@ nsEventListenerManager::RemoveEventListenerByType(nsIDOMEventListener *aListener
} }
nsListenerStruct* nsListenerStruct*
nsEventListenerManager::FindJSEventListener(uint32_t aEventType, nsEventListenerManager::FindEventHandler(uint32_t aEventType,
nsIAtom* aTypeAtom) nsIAtom* aTypeAtom)
{ {
// Run through the listeners for this type and see if a script // Run through the listeners for this type and see if a script
// listener is registered // listener is registered
@ -474,16 +474,16 @@ nsEventListenerManager::FindJSEventListener(uint32_t aEventType,
} }
nsresult nsresult
nsEventListenerManager::SetJSEventListener(nsIScriptContext *aContext, nsEventListenerManager::SetEventHandlerInternal(nsIScriptContext *aContext,
JSObject* aScopeObject, JSObject* aScopeObject,
nsIAtom* aName, nsIAtom* aName,
JSObject *aHandler, JSObject *aHandler,
bool aPermitUntrustedEvents, bool aPermitUntrustedEvents,
nsListenerStruct **aListenerStruct) nsListenerStruct **aListenerStruct)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
uint32_t eventType = nsContentUtils::GetEventId(aName); uint32_t eventType = nsContentUtils::GetEventId(aName);
nsListenerStruct* ls = FindJSEventListener(eventType, aName); nsListenerStruct* ls = FindEventHandler(eventType, aName);
if (!ls) { if (!ls) {
// If we didn't find a script listener or no listeners existed // If we didn't find a script listener or no listeners existed
@ -495,7 +495,7 @@ nsEventListenerManager::SetJSEventListener(nsIScriptContext *aContext,
AddEventListener(scriptListener, eventType, aName, AddEventListener(scriptListener, eventType, aName,
NS_EVENT_FLAG_BUBBLE | NS_PRIV_EVENT_FLAG_SCRIPT); NS_EVENT_FLAG_BUBBLE | NS_PRIV_EVENT_FLAG_SCRIPT);
ls = FindJSEventListener(eventType, aName); ls = FindEventHandler(eventType, aName);
} }
} else { } else {
ls->GetJSListener()->SetHandler(aHandler); ls->GetJSListener()->SetHandler(aHandler);
@ -517,11 +517,11 @@ nsEventListenerManager::SetJSEventListener(nsIScriptContext *aContext,
} }
nsresult nsresult
nsEventListenerManager::AddScriptEventListener(nsIAtom *aName, nsEventListenerManager::SetEventHandler(nsIAtom *aName,
const nsAString& aBody, const nsAString& aBody,
uint32_t aLanguage, uint32_t aLanguage,
bool aDeferCompilation, bool aDeferCompilation,
bool aPermitUntrustedEvents) bool aPermitUntrustedEvents)
{ {
NS_PRECONDITION(aLanguage != nsIProgrammingLanguage::UNKNOWN, NS_PRECONDITION(aLanguage != nsIProgrammingLanguage::UNKNOWN,
"Must know the language for the script event listener"); "Must know the language for the script event listener");
@ -627,8 +627,8 @@ nsEventListenerManager::AddScriptEventListener(nsIAtom *aName,
JSObject* scope = global->GetGlobalJSObject(); JSObject* scope = global->GetGlobalJSObject();
nsListenerStruct *ls; nsListenerStruct *ls;
rv = SetJSEventListener(context, scope, aName, nullptr, rv = SetEventHandlerInternal(context, scope, aName, nullptr,
aPermitUntrustedEvents, &ls); aPermitUntrustedEvents, &ls);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
if (!aDeferCompilation) { if (!aDeferCompilation) {
@ -639,10 +639,10 @@ nsEventListenerManager::AddScriptEventListener(nsIAtom *aName,
} }
void void
nsEventListenerManager::RemoveScriptEventListener(nsIAtom* aName) nsEventListenerManager::RemoveEventHandler(nsIAtom* aName)
{ {
uint32_t eventType = nsContentUtils::GetEventId(aName); uint32_t eventType = nsContentUtils::GetEventId(aName);
nsListenerStruct* ls = FindJSEventListener(eventType, aName); nsListenerStruct* ls = FindEventHandler(eventType, aName);
if (ls) { if (ls) {
mListeners.RemoveElementAt(uint32_t(ls - &mListeners.ElementAt(0))); mListeners.RemoveElementAt(uint32_t(ls - &mListeners.ElementAt(0)));
@ -1026,15 +1026,15 @@ nsEventListenerManager::HasUnloadListeners()
} }
nsresult nsresult
nsEventListenerManager::SetJSEventListenerToJsval(nsIAtom *aEventName, nsEventListenerManager::SetEventHandlerToJsval(nsIAtom *aEventName,
JSContext *cx, JSContext *cx,
JSObject* aScope, JSObject* aScope,
const jsval & v) const jsval & v)
{ {
JSObject *handler; JSObject *handler;
if (JSVAL_IS_PRIMITIVE(v) || if (JSVAL_IS_PRIMITIVE(v) ||
!JS_ObjectIsCallable(cx, handler = JSVAL_TO_OBJECT(v))) { !JS_ObjectIsCallable(cx, handler = JSVAL_TO_OBJECT(v))) {
RemoveScriptEventListener(aEventName); RemoveEventHandler(aEventName);
return NS_OK; return NS_OK;
} }
@ -1057,15 +1057,15 @@ nsEventListenerManager::SetJSEventListenerToJsval(nsIAtom *aEventName,
// Untrusted events are always permitted for non-chrome script // Untrusted events are always permitted for non-chrome script
// handlers. // handlers.
nsListenerStruct *ignored; nsListenerStruct *ignored;
return SetJSEventListener(context, scope, aEventName, handler, return SetEventHandlerInternal(context, scope, aEventName, handler,
!nsContentUtils::IsCallerChrome(), &ignored); !nsContentUtils::IsCallerChrome(), &ignored);
} }
void void
nsEventListenerManager::GetJSEventListener(nsIAtom *aEventName, jsval *vp) nsEventListenerManager::GetEventHandler(nsIAtom *aEventName, jsval *vp)
{ {
uint32_t eventType = nsContentUtils::GetEventId(aEventName); uint32_t eventType = nsContentUtils::GetEventId(aEventName);
nsListenerStruct* ls = FindJSEventListener(eventType, aEventName); nsListenerStruct* ls = FindEventHandler(eventType, aEventName);
*vp = JSVAL_NULL; *vp = JSVAL_NULL;

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

@ -101,15 +101,15 @@ public:
*/ */
// XXXbz does that play correctly with nodes being adopted across // XXXbz does that play correctly with nodes being adopted across
// documents? Need to double-check the spec here. // documents? Need to double-check the spec here.
nsresult AddScriptEventListener(nsIAtom *aName, nsresult SetEventHandler(nsIAtom *aName,
const nsAString& aFunc, const nsAString& aFunc,
uint32_t aLanguage, uint32_t aLanguage,
bool aDeferCompilation, bool aDeferCompilation,
bool aPermitUntrustedEvents); bool aPermitUntrustedEvents);
/** /**
* Remove the current "inline" event listener for aName. * Remove the current "inline" event listener for aName.
*/ */
void RemoveScriptEventListener(nsIAtom *aName); void RemoveEventHandler(nsIAtom *aName);
void HandleEvent(nsPresContext* aPresContext, void HandleEvent(nsPresContext* aPresContext,
nsEvent* aEvent, nsEvent* aEvent,
@ -242,7 +242,7 @@ protected:
/** /**
* Find the nsListenerStruct for the "inline" event listener for aTypeAtom. * Find the nsListenerStruct for the "inline" event listener for aTypeAtom.
*/ */
nsListenerStruct* FindJSEventListener(uint32_t aEventType, nsIAtom* aTypeAtom); nsListenerStruct* FindEventHandler(uint32_t aEventType, nsIAtom* aTypeAtom);
/** /**
* Set the "inline" event listener for aName to aHandler. aHandler * Set the "inline" event listener for aName to aHandler. aHandler
@ -250,12 +250,12 @@ protected:
* string for this listener. The nsListenerStruct that results, if * string for this listener. The nsListenerStruct that results, if
* any, is returned in aListenerStruct. * any, is returned in aListenerStruct.
*/ */
nsresult SetJSEventListener(nsIScriptContext *aContext, nsresult SetEventHandlerInternal(nsIScriptContext *aContext,
JSObject* aScopeGlobal, JSObject* aScopeGlobal,
nsIAtom* aName, nsIAtom* aName,
JSObject *aHandler, JSObject *aHandler,
bool aPermitUntrustedEvents, bool aPermitUntrustedEvents,
nsListenerStruct **aListenerStruct); nsListenerStruct **aListenerStruct);
bool IsDeviceType(uint32_t aType); bool IsDeviceType(uint32_t aType);
void EnableDevice(uint32_t aType); void EnableDevice(uint32_t aType);
@ -269,13 +269,13 @@ public:
* not be in the same compartment, though cx and v are guaranteed to * not be in the same compartment, though cx and v are guaranteed to
* be in the same compartment. * be in the same compartment.
*/ */
nsresult SetJSEventListenerToJsval(nsIAtom *aEventName, JSContext *cx, nsresult SetEventHandlerToJsval(nsIAtom *aEventName, JSContext *cx,
JSObject *aScope, const jsval &v); JSObject *aScope, const jsval &v);
/** /**
* Get the value of the "inline" event listener for aEventName. * Get the value of the "inline" event listener for aEventName.
* This may cause lazy compilation if the listener is uncompiled. * This may cause lazy compilation if the listener is uncompiled.
*/ */
void GetJSEventListener(nsIAtom *aEventName, jsval *vp); void GetEventHandler(nsIAtom *aEventName, jsval *vp);
protected: protected:
void AddEventListener(nsIDOMEventListener *aListener, void AddEventListener(nsIDOMEventListener *aListener,

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

@ -1903,7 +1903,7 @@ nsGenericHTMLElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
aValue) { aValue) {
NS_ABORT_IF_FALSE(aValue->Type() == nsAttrValue::eString, NS_ABORT_IF_FALSE(aValue->Type() == nsAttrValue::eString,
"Expected string value for script body"); "Expected string value for script body");
nsresult rv = AddScriptEventListener(aName, aValue->GetStringValue()); nsresult rv = SetEventHandler(aName, aValue->GetStringValue());
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }
else if (aNotify && aName == nsGkAtoms::spellcheck) { else if (aNotify && aName == nsGkAtoms::spellcheck) {
@ -2043,7 +2043,7 @@ nsGenericHTMLElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
EventNameType_HTML)) { EventNameType_HTML)) {
nsEventListenerManager* manager = GetListenerManager(false); nsEventListenerManager* manager = GetListenerManager(false);
if (manager) { if (manager) {
manager->RemoveScriptEventListener(aAttribute); manager->RemoveEventHandler(aAttribute);
} }
} }
@ -4085,7 +4085,7 @@ nsGenericHTMLElement::RecompileScriptEventListeners()
nsAutoString value; nsAutoString value;
GetAttr(kNameSpaceID_None, attr, value); GetAttr(kNameSpaceID_None, attr, value);
AddScriptEventListener(attr, value, true); SetEventHandler(attr, value, true);
} }
} }

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

@ -251,8 +251,8 @@ nsSVGElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
if (IsEventName(aName) && aValue) { if (IsEventName(aName) && aValue) {
NS_ABORT_IF_FALSE(aValue->Type() == nsAttrValue::eString, NS_ABORT_IF_FALSE(aValue->Type() == nsAttrValue::eString,
"Expected string value for script body"); "Expected string value for script body");
nsresult rv = AddScriptEventListener(GetEventNameForAttr(aName), nsresult rv = SetEventHandler(GetEventNameForAttr(aName),
aValue->GetStringValue()); aValue->GetStringValue());
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }
@ -606,7 +606,7 @@ nsSVGElement::UnsetAttrInternal(int32_t aNamespaceID, nsIAtom* aName,
nsEventListenerManager* manager = GetListenerManager(false); nsEventListenerManager* manager = GetListenerManager(false);
if (manager) { if (manager) {
nsIAtom* eventName = GetEventNameForAttr(aName); nsIAtom* eventName = GetEventNameForAttr(aName);
manager->RemoveScriptEventListener(eventName); manager->RemoveEventHandler(eventName);
} }
return; return;
} }
@ -2443,7 +2443,7 @@ nsSVGElement::RecompileScriptEventListeners()
nsAutoString value; nsAutoString value;
GetAttr(kNameSpaceID_None, attr, value); GetAttr(kNameSpaceID_None, attr, value);
AddScriptEventListener(GetEventNameForAttr(attr), value, true); SetEventHandler(GetEventNameForAttr(attr), value, true);
} }
} }

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

@ -656,7 +656,7 @@ nsXULElement::AddListenerFor(const nsAttrName& aName,
nsContentUtils::IsEventAttributeName(attr, EventNameType_XUL)) { nsContentUtils::IsEventAttributeName(attr, EventNameType_XUL)) {
nsAutoString value; nsAutoString value;
GetAttr(kNameSpaceID_None, attr, value); GetAttr(kNameSpaceID_None, attr, value);
AddScriptEventListener(attr, value, true); SetEventHandler(attr, value, true);
} }
} }
} }
@ -919,11 +919,11 @@ nsXULElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
MaybeAddPopupListener(aName); MaybeAddPopupListener(aName);
if (nsContentUtils::IsEventAttributeName(aName, EventNameType_XUL)) { if (nsContentUtils::IsEventAttributeName(aName, EventNameType_XUL)) {
if (aValue->Type() == nsAttrValue::eString) { if (aValue->Type() == nsAttrValue::eString) {
AddScriptEventListener(aName, aValue->GetStringValue(), true); SetEventHandler(aName, aValue->GetStringValue(), true);
} else { } else {
nsAutoString body; nsAutoString body;
aValue->ToString(body); aValue->ToString(body);
AddScriptEventListener(aName, body, true); SetEventHandler(aName, body, true);
} }
} }
@ -1853,7 +1853,7 @@ nsXULElement::RecompileScriptEventListeners()
nsAutoString value; nsAutoString value;
GetAttr(kNameSpaceID_None, attr, value); GetAttr(kNameSpaceID_None, attr, value);
AddScriptEventListener(attr, value, true); SetEventHandler(attr, value, true);
} }
} }

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

@ -11074,9 +11074,9 @@ nsGlobalWindow::SetHasAudioAvailableEventListeners()
#define EVENT(name_, id_, type_, struct_) \ #define EVENT(name_, id_, type_, struct_) \
NS_IMETHODIMP nsGlobalWindow::GetOn##name_(JSContext *cx, \ NS_IMETHODIMP nsGlobalWindow::GetOn##name_(JSContext *cx, \
jsval *vp) { \ jsval *vp) { \
nsEventListenerManager *elm = GetListenerManager(false); \ nsEventListenerManager *elm = GetListenerManager(false); \
if (elm) { \ if (elm) { \
elm->GetJSEventListener(nsGkAtoms::on##name_, vp); \ elm->GetEventHandler(nsGkAtoms::on##name_, vp); \
} else { \ } else { \
*vp = JSVAL_NULL; \ *vp = JSVAL_NULL; \
} \ } \
@ -11084,7 +11084,7 @@ nsGlobalWindow::SetHasAudioAvailableEventListeners()
} \ } \
NS_IMETHODIMP nsGlobalWindow::SetOn##name_(JSContext *cx, \ NS_IMETHODIMP nsGlobalWindow::SetOn##name_(JSContext *cx, \
const jsval &v) { \ const jsval &v) { \
nsEventListenerManager *elm = GetListenerManager(true); \ nsEventListenerManager *elm = GetListenerManager(true); \
if (!elm) { \ if (!elm) { \
return NS_ERROR_OUT_OF_MEMORY; \ return NS_ERROR_OUT_OF_MEMORY; \
} \ } \
@ -11093,7 +11093,7 @@ nsGlobalWindow::SetHasAudioAvailableEventListeners()
if (!obj) { \ if (!obj) { \
return NS_ERROR_UNEXPECTED; \ return NS_ERROR_UNEXPECTED; \
} \ } \
return elm->SetJSEventListenerToJsval(nsGkAtoms::on##name_, cx, obj, v); \ return elm->SetEventHandlerToJsval(nsGkAtoms::on##name_, cx, obj, v); \
} }
#define WINDOW_ONLY_EVENT EVENT #define WINDOW_ONLY_EVENT EVENT
#define TOUCH_EVENT EVENT #define TOUCH_EVENT EVENT