From 314f2ab5fd4779a355b7e182fd41668ff31d5b7a Mon Sep 17 00:00:00 2001 From: "roc+%cs.cmu.edu" Date: Wed, 14 Mar 2007 01:42:42 +0000 Subject: [PATCH] Bug 336682. Fix online/offline events to target and bubble propertly, and so that works. Patch by Chris Double, r+sr=jst,r=dbaron --- content/base/src/nsGkAtomList.h | 2 ++ .../html/content/src/nsGenericHTMLElement.cpp | 2 ++ dom/src/base/nsDOMClassInfo.cpp | 9 +++++++++ dom/src/base/nsDOMClassInfo.h | 2 ++ dom/src/base/nsGlobalWindow.cpp | 16 +++++++++++----- layout/style/nsCSSParser.cpp | 2 ++ 6 files changed, 28 insertions(+), 5 deletions(-) diff --git a/content/base/src/nsGkAtomList.h b/content/base/src/nsGkAtomList.h index 14c6693ce0b1..4a6826c1b2f8 100755 --- a/content/base/src/nsGkAtomList.h +++ b/content/base/src/nsGkAtomList.h @@ -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") diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index b46b808d203f..660930ab5f07 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -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 || diff --git a/dom/src/base/nsDOMClassInfo.cpp b/dom/src/base/nsDOMClassInfo.cpp index 32f0e7dd6e24..4276d35eb058 100644 --- a/dom/src/base/nsDOMClassInfo.cpp +++ b/dom/src/base/nsDOMClassInfo.cpp @@ -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' : diff --git a/dom/src/base/nsDOMClassInfo.h b/dom/src/base/nsDOMClassInfo.h index b8d2feb93977..1c67d662d8e5 100644 --- a/dom/src/base/nsDOMClassInfo.h +++ b/dom/src/base/nsDOMClassInfo.h @@ -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; diff --git a/dom/src/base/nsGlobalWindow.cpp b/dom/src/base/nsGlobalWindow.cpp index b8fe62585f50..46de4a247491 100644 --- a/dom/src/base/nsGlobalWindow.cpp +++ b/dom/src/base/nsGlobalWindow.cpp @@ -5960,9 +5960,8 @@ nsGlobalWindow::GetInterface(const nsIID & aIID, void **aSink) void nsGlobalWindow::FireOfflineStatusEvent() { - if (!mDocument) + if (!mDoc) return; - nsCOMPtr 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 eventTarget = doc.get(); - nsCOMPtr htmlDoc = do_QueryInterface(doc); + nsCOMPtr eventTarget = mDoc; + nsCOMPtr htmlDoc = do_QueryInterface(mDoc); if (htmlDoc) { nsCOMPtr 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 documentElement; + mDocument->GetDocumentElement(getter_AddRefs(documentElement)); + if(documentElement) { + eventTarget = documentElement; + } + } + nsContentUtils::DispatchTrustedEvent(mDoc, eventTarget, name, PR_TRUE, PR_FALSE); } nsresult diff --git a/layout/style/nsCSSParser.cpp b/layout/style/nsCSSParser.cpp index 2d158e4307bf..4965d23612ff 100644 --- a/layout/style/nsCSSParser.cpp +++ b/layout/style/nsCSSParser.cpp @@ -2399,6 +2399,8 @@ CSSParserImpl::ParseAttributeSelector(PRInt32& aDataMask, "onmousemove", "onmouseout", "onmouseup", + "onoffline", + "ononline", "onreset", "onselect", "onsubmit",