Fixing bug 233142. Correct event default action prevention logic to match what we used to do before bug 226462 was fixed. r=bzbarsky@mit.edu, sr=bryner@brianryner.com.

This commit is contained in:
jst%mozilla.jstenback.com 2004-02-20 20:46:22 +00:00
Родитель 32eb2c4962
Коммит f218d03481
4 изменённых файлов: 27 добавлений и 27 удалений

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

@ -1515,25 +1515,22 @@ nsresult nsEventListenerManager::HandleEvent(nsIPresContext* aPresContext,
// Try the type-specific listener interface // Try the type-specific listener interface
PRBool hasInterface = PR_FALSE; PRBool hasInterface = PR_FALSE;
if (typeData) if (typeData)
ret = DispatchToInterface(*aDOMEvent, ls->mListener, DispatchToInterface(*aDOMEvent, ls->mListener,
dispData->method, *typeData->iid, dispData->method, *typeData->iid,
&hasInterface); &hasInterface);
// If it doesn't implement that, call the generic HandleEvent() // If it doesn't implement that, call the generic HandleEvent()
if (!hasInterface && (ls->mSubType == NS_EVENT_BITS_NONE || if (!hasInterface && (ls->mSubType == NS_EVENT_BITS_NONE ||
ls->mSubType & dispData->bits)) ls->mSubType & dispData->bits))
ret = HandleEventSubType(ls, *aDOMEvent, aCurrentTarget, HandleEventSubType(ls, *aDOMEvent, aCurrentTarget,
dispData ? dispData->bits : NS_EVENT_BITS_NONE, dispData ? dispData->bits : NS_EVENT_BITS_NONE,
aFlags); aFlags);
} }
} }
} }
} }
// XXX (NS_OK != ret) is going away, if (aEvent->flags & NS_EVENT_FLAG_NO_DEFAULT) {
// (aEvent->flags & NS_EVENT_FLAG_NO_DEFAULT) is correct
if ((NS_OK != ret) ||
(aEvent->flags & NS_EVENT_FLAG_NO_DEFAULT)) {
*aEventStatus = nsEventStatus_eConsumeNoDefault; *aEventStatus = nsEventStatus_eConsumeNoDefault;
} }

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

@ -5025,7 +5025,6 @@ GlobalWindowImpl::RunTimeout(nsTimeoutImpl *aTimeout)
nsTimeoutImpl dummy_timeout; nsTimeoutImpl dummy_timeout;
JSContext *cx; JSContext *cx;
PRInt64 now, deadline; PRInt64 now, deadline;
nsresult rv;
PRUint32 firingDepth = mTimeoutFiringDepth + 1; PRUint32 firingDepth = mTimeoutFiringDepth + 1;
// Make sure that the window and the script context don't go away as // Make sure that the window and the script context don't go away as
@ -5124,10 +5123,10 @@ GlobalWindowImpl::RunTimeout(nsTimeoutImpl *aTimeout)
nsAutoString retval; nsAutoString retval;
PRBool is_undefined; PRBool is_undefined;
rv = mContext->EvaluateString(nsDependentString(script), mJSObject, mContext->EvaluateString(nsDependentString(script), mJSObject,
timeout->mPrincipal, timeout->mFileName, timeout->mPrincipal, timeout->mFileName,
timeout->mLineNo, timeout->mVersion, timeout->mLineNo, timeout->mVersion, retval,
retval, &is_undefined); &is_undefined);
} else { } else {
PRInt64 lateness64; PRInt64 lateness64;
PRInt32 lateness; PRInt32 lateness;
@ -5140,9 +5139,8 @@ GlobalWindowImpl::RunTimeout(nsTimeoutImpl *aTimeout)
timeout->mArgv[timeout->mArgc] = INT_TO_JSVAL((jsint) lateness); timeout->mArgv[timeout->mArgc] = INT_TO_JSVAL((jsint) lateness);
jsval dummy; jsval dummy;
rv = mContext->CallEventHandler(mJSObject, timeout->mFunObj, mContext->CallEventHandler(mJSObject, timeout->mFunObj,
timeout->mArgc + 1, timeout->mArgv, timeout->mArgc + 1, timeout->mArgv, &dummy);
&dummy);
} }
--mTimeoutFiringDepth; --mTimeoutFiringDepth;
@ -5209,9 +5207,9 @@ GlobalWindowImpl::RunTimeout(nsTimeoutImpl *aTimeout)
// Reschedule the OS timer. Don't bother returning any error // Reschedule the OS timer. Don't bother returning any error
// codes if this fails since nobody who cares about them is // codes if this fails since nobody who cares about them is
// listening anyways. // listening anyways.
rv = timeout->mTimer->InitWithFuncCallback(TimerCallback, timeout, nsresult rv =
delay32, timeout->mTimer->InitWithFuncCallback(TimerCallback, timeout, delay32,
nsITimer::TYPE_ONE_SHOT); nsITimer::TYPE_ONE_SHOT);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
NS_ERROR("Error initializing timer for DOM timeout!"); NS_ERROR("Error initializing timer for DOM timeout!");

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

@ -1277,13 +1277,16 @@ nsJSContext::CallEventHandler(JSObject *aTarget, JSObject *aHandler,
// Don't pass back results from failed calls. // Don't pass back results from failed calls.
*rval = JSVAL_VOID; *rval = JSVAL_VOID;
// Tell the caller that the handler threw an error.
rv = NS_ERROR_FAILURE;
} }
} }
if (NS_FAILED(stack->Pop(nsnull))) if (NS_FAILED(stack->Pop(nsnull)))
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
return NS_OK; return rv;
} }
nsresult nsresult

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

@ -100,7 +100,8 @@ nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent)
return NS_OK; return NS_OK;
} }
//if (mReturnResult == nsReturnResult_eNotSet) { //if (mReturnResult == nsReturnResult_eNotSet) {
if (eventString.Equals(NS_LITERAL_STRING("error")) || eventString.Equals(NS_LITERAL_STRING("mouseover"))) { if (eventString.Equals(NS_LITERAL_STRING("error")) ||
eventString.Equals(NS_LITERAL_STRING("mouseover"))) {
mReturnResult = nsReturnResult_eReverseReturnResult; mReturnResult = nsReturnResult_eReverseReturnResult;
} }
else { else {
@ -197,18 +198,19 @@ nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent)
beforeUnload->text = nsDependentJSString(JSVAL_TO_STRING(rval)); beforeUnload->text = nsDependentJSString(JSVAL_TO_STRING(rval));
} }
} }
} else { } else if (JSVAL_IS_BOOLEAN(rval)) {
// if the handler returned false and its sense is not reversed, // if the handler returned false and its sense is not reversed,
// or the handler returned true and its sense is reversed from // or the handler returned true and its sense is reversed from
// the usual (false means cancel), then prevent default. // the usual (false means cancel), then prevent default.
PRBool jsBoolResult = !JSVAL_IS_BOOLEAN(rval) || JSVAL_TO_BOOLEAN(rval); if (JSVAL_TO_BOOLEAN(rval) ==
if (jsBoolResult ==
(mReturnResult == nsReturnResult_eReverseReturnResult)) { (mReturnResult == nsReturnResult_eReverseReturnResult)) {
aEvent->PreventDefault(); aEvent->PreventDefault();
} }
} }
} else if (eventString.Equals(NS_LITERAL_STRING("onsubmit"))) {
// Don't submit any data if the event handler failed
aEvent->PreventDefault();
} }
return rv; return rv;