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

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

@ -210,9 +210,9 @@ public:
* @param aValue the JS to attach
* @param aDefer indicates if deferred execution is allowed
*/
nsresult AddScriptEventListener(nsIAtom* aEventName,
const nsAString& aValue,
bool aDefer = true);
nsresult SetEventHandler(nsIAtom* aEventName,
const nsAString& aValue,
bool aDefer = true);
/**
* 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_) \
NS_IMETHODIMP nsINode::GetOn##name_(JSContext *cx, jsval *vp) { \
nsEventListenerManager *elm = GetListenerManager(false); \
nsEventListenerManager *elm = GetListenerManager(false); \
if (elm) { \
elm->GetJSEventListener(nsGkAtoms::on##name_, vp); \
elm->GetEventHandler(nsGkAtoms::on##name_, vp); \
} else { \
*vp = JSVAL_NULL; \
} \
return NS_OK; \
} \
NS_IMETHODIMP nsINode::SetOn##name_(JSContext *cx, const jsval &v) { \
nsEventListenerManager *elm = GetListenerManager(true); \
nsEventListenerManager *elm = GetListenerManager(true); \
if (!elm) { \
return NS_ERROR_OUT_OF_MEMORY; \
} \
@ -1983,7 +1983,7 @@ nsINode::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
/* Just silently do nothing */ \
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 DOCUMENT_ONLY_EVENT EVENT

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

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

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

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

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

@ -1903,7 +1903,7 @@ nsGenericHTMLElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
aValue) {
NS_ABORT_IF_FALSE(aValue->Type() == nsAttrValue::eString,
"Expected string value for script body");
nsresult rv = AddScriptEventListener(aName, aValue->GetStringValue());
nsresult rv = SetEventHandler(aName, aValue->GetStringValue());
NS_ENSURE_SUCCESS(rv, rv);
}
else if (aNotify && aName == nsGkAtoms::spellcheck) {
@ -2043,7 +2043,7 @@ nsGenericHTMLElement::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
EventNameType_HTML)) {
nsEventListenerManager* manager = GetListenerManager(false);
if (manager) {
manager->RemoveScriptEventListener(aAttribute);
manager->RemoveEventHandler(aAttribute);
}
}
@ -4085,7 +4085,7 @@ nsGenericHTMLElement::RecompileScriptEventListeners()
nsAutoString 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) {
NS_ABORT_IF_FALSE(aValue->Type() == nsAttrValue::eString,
"Expected string value for script body");
nsresult rv = AddScriptEventListener(GetEventNameForAttr(aName),
aValue->GetStringValue());
nsresult rv = SetEventHandler(GetEventNameForAttr(aName),
aValue->GetStringValue());
NS_ENSURE_SUCCESS(rv, rv);
}
@ -606,7 +606,7 @@ nsSVGElement::UnsetAttrInternal(int32_t aNamespaceID, nsIAtom* aName,
nsEventListenerManager* manager = GetListenerManager(false);
if (manager) {
nsIAtom* eventName = GetEventNameForAttr(aName);
manager->RemoveScriptEventListener(eventName);
manager->RemoveEventHandler(eventName);
}
return;
}
@ -2443,7 +2443,7 @@ nsSVGElement::RecompileScriptEventListeners()
nsAutoString 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)) {
nsAutoString 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);
if (nsContentUtils::IsEventAttributeName(aName, EventNameType_XUL)) {
if (aValue->Type() == nsAttrValue::eString) {
AddScriptEventListener(aName, aValue->GetStringValue(), true);
SetEventHandler(aName, aValue->GetStringValue(), true);
} else {
nsAutoString body;
aValue->ToString(body);
AddScriptEventListener(aName, body, true);
SetEventHandler(aName, body, true);
}
}
@ -1853,7 +1853,7 @@ nsXULElement::RecompileScriptEventListeners()
nsAutoString 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_) \
NS_IMETHODIMP nsGlobalWindow::GetOn##name_(JSContext *cx, \
jsval *vp) { \
nsEventListenerManager *elm = GetListenerManager(false); \
nsEventListenerManager *elm = GetListenerManager(false); \
if (elm) { \
elm->GetJSEventListener(nsGkAtoms::on##name_, vp); \
elm->GetEventHandler(nsGkAtoms::on##name_, vp); \
} else { \
*vp = JSVAL_NULL; \
} \
@ -11084,7 +11084,7 @@ nsGlobalWindow::SetHasAudioAvailableEventListeners()
} \
NS_IMETHODIMP nsGlobalWindow::SetOn##name_(JSContext *cx, \
const jsval &v) { \
nsEventListenerManager *elm = GetListenerManager(true); \
nsEventListenerManager *elm = GetListenerManager(true); \
if (!elm) { \
return NS_ERROR_OUT_OF_MEMORY; \
} \
@ -11093,7 +11093,7 @@ nsGlobalWindow::SetHasAudioAvailableEventListeners()
if (!obj) { \
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 TOUCH_EVENT EVENT