Bug 336682. Fix online/offline events to target and bubble propertly, and so that <body ononline= onoffline=> works. Patch by Chris Double, r+sr=jst,r=dbaron

This commit is contained in:
roc+%cs.cmu.edu 2007-03-14 01:42:42 +00:00
parent 826e728ee9
commit 314f2ab5fd
6 changed files with 28 additions and 5 deletions

View File

@ -578,6 +578,8 @@ GK_ATOM(onmousemove, "onmousemove")
GK_ATOM(onmouseout, "onmouseout")
GK_ATOM(onmouseover, "onmouseover")
GK_ATOM(onmouseup, "onmouseup")
GK_ATOM(ononline, "ononline")
GK_ATOM(onoffline, "onoffline")
GK_ATOM(onoverflow, "onoverflow")
GK_ATOM(onoverflowchanged, "onoverflowchanged")
GK_ATOM(onpagehide, "onpagehide")

View File

@ -1442,6 +1442,8 @@ PRBool nsGenericHTMLElement::IsEventName(nsIAtom* aName)
aName == nsGkAtoms::onerror ||
aName == nsGkAtoms::onfocus ||
aName == nsGkAtoms::onblur ||
aName == nsGkAtoms::onoffline ||
aName == nsGkAtoms::ononline ||
aName == nsGkAtoms::onsubmit ||
aName == nsGkAtoms::onreset ||
aName == nsGkAtoms::onchange ||

View File

@ -1228,6 +1228,8 @@ jsval nsDOMClassInfo::sOnkeypress_id = JSVAL_VOID;
jsval nsDOMClassInfo::sOnmousemove_id = JSVAL_VOID;
jsval nsDOMClassInfo::sOnfocus_id = JSVAL_VOID;
jsval nsDOMClassInfo::sOnblur_id = JSVAL_VOID;
jsval nsDOMClassInfo::sOnonline_id = JSVAL_VOID;
jsval nsDOMClassInfo::sOnoffline_id = JSVAL_VOID;
jsval nsDOMClassInfo::sOnsubmit_id = JSVAL_VOID;
jsval nsDOMClassInfo::sOnreset_id = JSVAL_VOID;
jsval nsDOMClassInfo::sOnchange_id = JSVAL_VOID;
@ -1419,6 +1421,8 @@ nsDOMClassInfo::DefineStaticJSVals(JSContext *cx)
SET_JSVAL_TO_STRING(sOnmousemove_id, cx, "onmousemove");
SET_JSVAL_TO_STRING(sOnfocus_id, cx, "onfocus");
SET_JSVAL_TO_STRING(sOnblur_id, cx, "onblur");
SET_JSVAL_TO_STRING(sOnoffline_id, cx, "onoffline");
SET_JSVAL_TO_STRING(sOnonline_id, cx, "ononline");
SET_JSVAL_TO_STRING(sOnsubmit_id, cx, "onsubmit");
SET_JSVAL_TO_STRING(sOnreset_id, cx, "onreset");
SET_JSVAL_TO_STRING(sOnchange_id, cx, "onchange");
@ -3843,6 +3847,8 @@ nsDOMClassInfo::ShutDown()
sOnmousemove_id = JSVAL_VOID;
sOnfocus_id = JSVAL_VOID;
sOnblur_id = JSVAL_VOID;
sOnoffline_id = JSVAL_VOID;
sOnonline_id = JSVAL_VOID;
sOnsubmit_id = JSVAL_VOID;
sOnreset_id = JSVAL_VOID;
sOnchange_id = JSVAL_VOID;
@ -6503,6 +6509,9 @@ nsEventReceiverSH::ReallyIsEventName(jsval id, jschar aFirstChar)
return (id == sOnkeydown_id ||
id == sOnkeypress_id ||
id == sOnkeyup_id);
case 'o' :
return (id == sOnoffline_id ||
id == sOnonline_id);
case 'u' :
return id == sOnunload_id;
case 'm' :

View File

@ -279,6 +279,8 @@ protected:
static jsval sOnmousemove_id;
static jsval sOnfocus_id;
static jsval sOnblur_id;
static jsval sOnonline_id;
static jsval sOnoffline_id;
static jsval sOnsubmit_id;
static jsval sOnreset_id;
static jsval sOnchange_id;

View File

@ -5960,9 +5960,8 @@ nsGlobalWindow::GetInterface(const nsIID & aIID, void **aSink)
void
nsGlobalWindow::FireOfflineStatusEvent()
{
if (!mDocument)
if (!mDoc)
return;
nsCOMPtr<nsIDocument> doc(do_QueryInterface(mDocument));
nsAutoString name;
if (NS_IsOffline()) {
name.AssignLiteral("offline");
@ -5971,8 +5970,8 @@ nsGlobalWindow::FireOfflineStatusEvent()
}
// The event is fired at the body element, or if there is no body element,
// at the document.
nsCOMPtr<nsISupports> eventTarget = doc.get();
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(doc);
nsCOMPtr<nsISupports> eventTarget = mDoc;
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(mDoc);
if (htmlDoc) {
nsCOMPtr<nsIDOMHTMLElement> body;
htmlDoc->GetBody(getter_AddRefs(body));
@ -5980,7 +5979,14 @@ nsGlobalWindow::FireOfflineStatusEvent()
eventTarget = body;
}
}
nsContentUtils::DispatchTrustedEvent(doc, eventTarget, name, PR_TRUE, PR_FALSE);
else {
nsCOMPtr<nsIDOMElement> documentElement;
mDocument->GetDocumentElement(getter_AddRefs(documentElement));
if(documentElement) {
eventTarget = documentElement;
}
}
nsContentUtils::DispatchTrustedEvent(mDoc, eventTarget, name, PR_TRUE, PR_FALSE);
}
nsresult

View File

@ -2399,6 +2399,8 @@ CSSParserImpl::ParseAttributeSelector(PRInt32& aDataMask,
"onmousemove",
"onmouseout",
"onmouseup",
"onoffline",
"ononline",
"onreset",
"onselect",
"onsubmit",