diff --git a/mozilla/content/xul/content/src/nsXULPopupListener.cpp b/mozilla/content/xul/content/src/nsXULPopupListener.cpp index f4e2c0b7dc4..ff70fbc2782 100644 --- a/mozilla/content/xul/content/src/nsXULPopupListener.cpp +++ b/mozilla/content/xul/content/src/nsXULPopupListener.cpp @@ -222,6 +222,8 @@ XULPopupListenerImpl::LaunchPopup(nsIDOMEvent* anEvent) nsString popupAlignment("topleft"); element->GetAttribute("popupalign", popupAlignment); + // Set the popup in the document for the duration of this call. + xulDocument->SetPopup(element); if (anchorAlignment == "") { // We aren't anchored. Create on the point. // Retrieve our x and y position. @@ -239,6 +241,7 @@ XULPopupListenerImpl::LaunchPopup(nsIDOMEvent* anEvent) domWindow->CreateAnchoredPopup(element, popupContent, anchorAlignment, type, popupAlignment); } + xulDocument->SetPopup(nsnull); } NS_RELEASE(global); } diff --git a/mozilla/content/xul/document/src/nsXULDocument.cpp b/mozilla/content/xul/document/src/nsXULDocument.cpp index cac62140526..3773af528d7 100644 --- a/mozilla/content/xul/document/src/nsXULDocument.cpp +++ b/mozilla/content/xul/document/src/nsXULDocument.cpp @@ -746,6 +746,7 @@ protected: nsString mCommand; nsIRDFResource* mFragmentRoot; // [OWNER] nsVoidArray mSubDocuments; // [OWNER] of subelements + nsIDOMElement* mPopup; // [OWNER] of this popup element in the doc }; PRInt32 XULDocumentImpl::gRefCnt = 0; @@ -781,7 +782,8 @@ XULDocumentImpl::XULDocumentImpl(void) mContentViewerContainer(nsnull), mCommand(""), mFragmentRoot(nsnull), - mListenerManager(nsnull) + mListenerManager(nsnull), + mPopup(nsnull) { NS_INIT_REFCNT(); @@ -827,6 +829,8 @@ XULDocumentImpl::~XULDocumentImpl() NS_IF_RELEASE(mListenerManager); + NS_IF_RELEASE(mPopup); + // mParentDocument is never refcounted // Delete references to sub-documents PRInt32 index = mSubDocuments.Count(); @@ -2684,6 +2688,23 @@ XULDocumentImpl::GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets) //////////////////////////////////////////////////////////////////////// // nsIDOMXULDocument interface +NS_IMETHODIMP +XULDocumentImpl::GetPopup(nsIDOMElement** anElement) +{ + *anElement = mPopup; + NS_IF_ADDREF(mPopup); + return NS_OK; +} + +NS_IMETHODIMP +XULDocumentImpl::SetPopup(nsIDOMElement* anElement) +{ + NS_IF_RELEASE(mPopup); + NS_IF_ADDREF(anElement); + mPopup = anElement; + return NS_OK; +} + NS_IMETHODIMP XULDocumentImpl::GetElementById(const nsString& aId, nsIDOMElement** aReturn) { diff --git a/mozilla/dom/public/idl/xul/XULDocument.idl b/mozilla/dom/public/idl/xul/XULDocument.idl index 77bc7aa0594..a6da54eba8d 100644 --- a/mozilla/dom/public/idl/xul/XULDocument.idl +++ b/mozilla/dom/public/idl/xul/XULDocument.idl @@ -3,7 +3,8 @@ interface XULDocument : Document { /* IID: { 0x17ddd8c0, 0xc5f8, 0x11d2, \ { 0xa6, 0xae, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } } */ - Element getElementById(in DOMString id); + attribute Element popup; + Element getElementById(in DOMString id); NodeList getElementsByAttribute(in DOMString name, in DOMString value); }; diff --git a/mozilla/dom/public/xul/nsIDOMXULDocument.h b/mozilla/dom/public/xul/nsIDOMXULDocument.h index 384aea3907d..68696006e6f 100644 --- a/mozilla/dom/public/xul/nsIDOMXULDocument.h +++ b/mozilla/dom/public/xul/nsIDOMXULDocument.h @@ -36,6 +36,9 @@ class nsIDOMXULDocument : public nsIDOMDocument { public: static const nsIID& GetIID() { static nsIID iid = NS_IDOMXULDOCUMENT_IID; return iid; } + NS_IMETHOD GetPopup(nsIDOMElement** aPopup)=0; + NS_IMETHOD SetPopup(nsIDOMElement* aPopup)=0; + NS_IMETHOD GetElementById(const nsString& aId, nsIDOMElement** aReturn)=0; NS_IMETHOD GetElementsByAttribute(const nsString& aName, const nsString& aValue, nsIDOMNodeList** aReturn)=0; @@ -43,12 +46,16 @@ public: #define NS_DECL_IDOMXULDOCUMENT \ + NS_IMETHOD GetPopup(nsIDOMElement** aPopup); \ + NS_IMETHOD SetPopup(nsIDOMElement* aPopup); \ NS_IMETHOD GetElementById(const nsString& aId, nsIDOMElement** aReturn); \ NS_IMETHOD GetElementsByAttribute(const nsString& aName, const nsString& aValue, nsIDOMNodeList** aReturn); \ #define NS_FORWARD_IDOMXULDOCUMENT(_to) \ + NS_IMETHOD GetPopup(nsIDOMElement** aPopup) { return _to GetPopup(aPopup); } \ + NS_IMETHOD SetPopup(nsIDOMElement* aPopup) { return _to SetPopup(aPopup); } \ NS_IMETHOD GetElementById(const nsString& aId, nsIDOMElement** aReturn) { return _to GetElementById(aId, aReturn); } \ NS_IMETHOD GetElementsByAttribute(const nsString& aName, const nsString& aValue, nsIDOMNodeList** aReturn) { return _to GetElementsByAttribute(aName, aValue, aReturn); } \ diff --git a/mozilla/dom/src/xul/nsJSXULDocument.cpp b/mozilla/dom/src/xul/nsJSXULDocument.cpp index 024ae70825e..29225c9634a 100644 --- a/mozilla/dom/src/xul/nsJSXULDocument.cpp +++ b/mozilla/dom/src/xul/nsJSXULDocument.cpp @@ -42,6 +42,12 @@ NS_DEF_PTR(nsIDOMElement); NS_DEF_PTR(nsIDOMXULDocument); NS_DEF_PTR(nsIDOMNodeList); +// +// XULDocument property ids +// +enum XULDocument_slots { + XULDOCUMENT_POPUP = -1 +}; /***********************************************************************/ // @@ -59,7 +65,18 @@ GetXULDocumentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) if (JSVAL_IS_INT(id)) { switch(JSVAL_TO_INT(id)) { - case 0: + case XULDOCUMENT_POPUP: + { + nsIDOMElement* prop; + if (NS_OK == a->GetPopup(&prop)) { + // get the js object + nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, vp); + } + else { + return JS_FALSE; + } + break; + } default: return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp); } @@ -87,7 +104,19 @@ SetXULDocumentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) if (JSVAL_IS_INT(id)) { switch(JSVAL_TO_INT(id)) { - case 0: + case XULDOCUMENT_POPUP: + { + nsIDOMElement* prop; + if (PR_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&prop, + kIElementIID, "Element", + cx, *vp)) { + return JS_FALSE; + } + + a->SetPopup(prop); + NS_IF_RELEASE(prop); + break; + } default: return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp); } @@ -213,7 +242,7 @@ XULDocumentGetElementsByAttribute(JSContext *cx, JSObject *obj, uintN argc, jsva // JSClass XULDocumentClass = { "XULDocument", - JSCLASS_HAS_PRIVATE, + JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS, JS_PropertyStub, JS_PropertyStub, GetXULDocumentProperty, @@ -230,6 +259,7 @@ JSClass XULDocumentClass = { // static JSPropertySpec XULDocumentProperties[] = { + {"popup", XULDOCUMENT_POPUP, JSPROP_ENUMERATE}, {0} }; diff --git a/mozilla/dom/src/xul/nsJSXULElement.cpp b/mozilla/dom/src/xul/nsJSXULElement.cpp index dc1646c407c..395ae855591 100644 --- a/mozilla/dom/src/xul/nsJSXULElement.cpp +++ b/mozilla/dom/src/xul/nsJSXULElement.cpp @@ -319,7 +319,7 @@ XULElementGetElementsByAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval // JSClass XULElementClass = { "XULElement", - JSCLASS_HAS_PRIVATE, + JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS, JS_PropertyStub, JS_PropertyStub, GetXULElementProperty, diff --git a/mozilla/dom/src/xul/nsJSXULTreeElement.cpp b/mozilla/dom/src/xul/nsJSXULTreeElement.cpp index 5c355fb13ae..9a9712c10d4 100644 --- a/mozilla/dom/src/xul/nsJSXULTreeElement.cpp +++ b/mozilla/dom/src/xul/nsJSXULTreeElement.cpp @@ -161,7 +161,7 @@ ResolveXULTreeElement(JSContext *cx, JSObject *obj, jsval id) // JSClass XULTreeElementClass = { "XULTreeElement", - JSCLASS_HAS_PRIVATE, + JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS, JS_PropertyStub, JS_PropertyStub, GetXULTreeElementProperty, diff --git a/mozilla/rdf/content/public/idl/XULDocument.idl b/mozilla/rdf/content/public/idl/XULDocument.idl index 77bc7aa0594..a6da54eba8d 100644 --- a/mozilla/rdf/content/public/idl/XULDocument.idl +++ b/mozilla/rdf/content/public/idl/XULDocument.idl @@ -3,7 +3,8 @@ interface XULDocument : Document { /* IID: { 0x17ddd8c0, 0xc5f8, 0x11d2, \ { 0xa6, 0xae, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } } */ - Element getElementById(in DOMString id); + attribute Element popup; + Element getElementById(in DOMString id); NodeList getElementsByAttribute(in DOMString name, in DOMString value); }; diff --git a/mozilla/rdf/content/public/nsIDOMXULDocument.h b/mozilla/rdf/content/public/nsIDOMXULDocument.h index 384aea3907d..68696006e6f 100644 --- a/mozilla/rdf/content/public/nsIDOMXULDocument.h +++ b/mozilla/rdf/content/public/nsIDOMXULDocument.h @@ -36,6 +36,9 @@ class nsIDOMXULDocument : public nsIDOMDocument { public: static const nsIID& GetIID() { static nsIID iid = NS_IDOMXULDOCUMENT_IID; return iid; } + NS_IMETHOD GetPopup(nsIDOMElement** aPopup)=0; + NS_IMETHOD SetPopup(nsIDOMElement* aPopup)=0; + NS_IMETHOD GetElementById(const nsString& aId, nsIDOMElement** aReturn)=0; NS_IMETHOD GetElementsByAttribute(const nsString& aName, const nsString& aValue, nsIDOMNodeList** aReturn)=0; @@ -43,12 +46,16 @@ public: #define NS_DECL_IDOMXULDOCUMENT \ + NS_IMETHOD GetPopup(nsIDOMElement** aPopup); \ + NS_IMETHOD SetPopup(nsIDOMElement* aPopup); \ NS_IMETHOD GetElementById(const nsString& aId, nsIDOMElement** aReturn); \ NS_IMETHOD GetElementsByAttribute(const nsString& aName, const nsString& aValue, nsIDOMNodeList** aReturn); \ #define NS_FORWARD_IDOMXULDOCUMENT(_to) \ + NS_IMETHOD GetPopup(nsIDOMElement** aPopup) { return _to GetPopup(aPopup); } \ + NS_IMETHOD SetPopup(nsIDOMElement* aPopup) { return _to SetPopup(aPopup); } \ NS_IMETHOD GetElementById(const nsString& aId, nsIDOMElement** aReturn) { return _to GetElementById(aId, aReturn); } \ NS_IMETHOD GetElementsByAttribute(const nsString& aName, const nsString& aValue, nsIDOMNodeList** aReturn) { return _to GetElementsByAttribute(aName, aValue, aReturn); } \ diff --git a/mozilla/rdf/content/src/nsJSElementObserver.cpp b/mozilla/rdf/content/src/nsJSElementObserver.cpp index d13cda25fd7..cdb1ef70477 100644 --- a/mozilla/rdf/content/src/nsJSElementObserver.cpp +++ b/mozilla/rdf/content/src/nsJSElementObserver.cpp @@ -331,7 +331,7 @@ ElementObserverOnRemoveAttributeNode(JSContext *cx, JSObject *obj, uintN argc, j // JSClass ElementObserverClass = { "ElementObserver", - JSCLASS_HAS_PRIVATE, + JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS, JS_PropertyStub, JS_PropertyStub, GetElementObserverProperty, diff --git a/mozilla/rdf/content/src/nsJSNodeObserver.cpp b/mozilla/rdf/content/src/nsJSNodeObserver.cpp index 349e45071d1..14f697594ce 100644 --- a/mozilla/rdf/content/src/nsJSNodeObserver.cpp +++ b/mozilla/rdf/content/src/nsJSNodeObserver.cpp @@ -400,7 +400,7 @@ NodeObserverOnAppendChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, // JSClass NodeObserverClass = { "NodeObserver", - JSCLASS_HAS_PRIVATE, + JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS, JS_PropertyStub, JS_PropertyStub, GetNodeObserverProperty, diff --git a/mozilla/rdf/content/src/nsJSXULDocument.cpp b/mozilla/rdf/content/src/nsJSXULDocument.cpp index 024ae70825e..29225c9634a 100644 --- a/mozilla/rdf/content/src/nsJSXULDocument.cpp +++ b/mozilla/rdf/content/src/nsJSXULDocument.cpp @@ -42,6 +42,12 @@ NS_DEF_PTR(nsIDOMElement); NS_DEF_PTR(nsIDOMXULDocument); NS_DEF_PTR(nsIDOMNodeList); +// +// XULDocument property ids +// +enum XULDocument_slots { + XULDOCUMENT_POPUP = -1 +}; /***********************************************************************/ // @@ -59,7 +65,18 @@ GetXULDocumentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) if (JSVAL_IS_INT(id)) { switch(JSVAL_TO_INT(id)) { - case 0: + case XULDOCUMENT_POPUP: + { + nsIDOMElement* prop; + if (NS_OK == a->GetPopup(&prop)) { + // get the js object + nsJSUtils::nsConvertObjectToJSVal((nsISupports *)prop, cx, vp); + } + else { + return JS_FALSE; + } + break; + } default: return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp); } @@ -87,7 +104,19 @@ SetXULDocumentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) if (JSVAL_IS_INT(id)) { switch(JSVAL_TO_INT(id)) { - case 0: + case XULDOCUMENT_POPUP: + { + nsIDOMElement* prop; + if (PR_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&prop, + kIElementIID, "Element", + cx, *vp)) { + return JS_FALSE; + } + + a->SetPopup(prop); + NS_IF_RELEASE(prop); + break; + } default: return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp); } @@ -213,7 +242,7 @@ XULDocumentGetElementsByAttribute(JSContext *cx, JSObject *obj, uintN argc, jsva // JSClass XULDocumentClass = { "XULDocument", - JSCLASS_HAS_PRIVATE, + JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS, JS_PropertyStub, JS_PropertyStub, GetXULDocumentProperty, @@ -230,6 +259,7 @@ JSClass XULDocumentClass = { // static JSPropertySpec XULDocumentProperties[] = { + {"popup", XULDOCUMENT_POPUP, JSPROP_ENUMERATE}, {0} }; diff --git a/mozilla/rdf/content/src/nsJSXULElement.cpp b/mozilla/rdf/content/src/nsJSXULElement.cpp index dc1646c407c..395ae855591 100644 --- a/mozilla/rdf/content/src/nsJSXULElement.cpp +++ b/mozilla/rdf/content/src/nsJSXULElement.cpp @@ -319,7 +319,7 @@ XULElementGetElementsByAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval // JSClass XULElementClass = { "XULElement", - JSCLASS_HAS_PRIVATE, + JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS, JS_PropertyStub, JS_PropertyStub, GetXULElementProperty, diff --git a/mozilla/rdf/content/src/nsJSXULTreeElement.cpp b/mozilla/rdf/content/src/nsJSXULTreeElement.cpp index 5c355fb13ae..9a9712c10d4 100644 --- a/mozilla/rdf/content/src/nsJSXULTreeElement.cpp +++ b/mozilla/rdf/content/src/nsJSXULTreeElement.cpp @@ -161,7 +161,7 @@ ResolveXULTreeElement(JSContext *cx, JSObject *obj, jsval id) // JSClass XULTreeElementClass = { "XULTreeElement", - JSCLASS_HAS_PRIVATE, + JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS, JS_PropertyStub, JS_PropertyStub, GetXULTreeElementProperty, diff --git a/mozilla/rdf/content/src/nsXULDocument.cpp b/mozilla/rdf/content/src/nsXULDocument.cpp index cac62140526..3773af528d7 100644 --- a/mozilla/rdf/content/src/nsXULDocument.cpp +++ b/mozilla/rdf/content/src/nsXULDocument.cpp @@ -746,6 +746,7 @@ protected: nsString mCommand; nsIRDFResource* mFragmentRoot; // [OWNER] nsVoidArray mSubDocuments; // [OWNER] of subelements + nsIDOMElement* mPopup; // [OWNER] of this popup element in the doc }; PRInt32 XULDocumentImpl::gRefCnt = 0; @@ -781,7 +782,8 @@ XULDocumentImpl::XULDocumentImpl(void) mContentViewerContainer(nsnull), mCommand(""), mFragmentRoot(nsnull), - mListenerManager(nsnull) + mListenerManager(nsnull), + mPopup(nsnull) { NS_INIT_REFCNT(); @@ -827,6 +829,8 @@ XULDocumentImpl::~XULDocumentImpl() NS_IF_RELEASE(mListenerManager); + NS_IF_RELEASE(mPopup); + // mParentDocument is never refcounted // Delete references to sub-documents PRInt32 index = mSubDocuments.Count(); @@ -2684,6 +2688,23 @@ XULDocumentImpl::GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets) //////////////////////////////////////////////////////////////////////// // nsIDOMXULDocument interface +NS_IMETHODIMP +XULDocumentImpl::GetPopup(nsIDOMElement** anElement) +{ + *anElement = mPopup; + NS_IF_ADDREF(mPopup); + return NS_OK; +} + +NS_IMETHODIMP +XULDocumentImpl::SetPopup(nsIDOMElement* anElement) +{ + NS_IF_RELEASE(mPopup); + NS_IF_ADDREF(anElement); + mPopup = anElement; + return NS_OK; +} + NS_IMETHODIMP XULDocumentImpl::GetElementById(const nsString& aId, nsIDOMElement** aReturn) { diff --git a/mozilla/rdf/content/src/nsXULPopupListener.cpp b/mozilla/rdf/content/src/nsXULPopupListener.cpp index f4e2c0b7dc4..ff70fbc2782 100644 --- a/mozilla/rdf/content/src/nsXULPopupListener.cpp +++ b/mozilla/rdf/content/src/nsXULPopupListener.cpp @@ -222,6 +222,8 @@ XULPopupListenerImpl::LaunchPopup(nsIDOMEvent* anEvent) nsString popupAlignment("topleft"); element->GetAttribute("popupalign", popupAlignment); + // Set the popup in the document for the duration of this call. + xulDocument->SetPopup(element); if (anchorAlignment == "") { // We aren't anchored. Create on the point. // Retrieve our x and y position. @@ -239,6 +241,7 @@ XULPopupListenerImpl::LaunchPopup(nsIDOMEvent* anEvent) domWindow->CreateAnchoredPopup(element, popupContent, anchorAlignment, type, popupAlignment); } + xulDocument->SetPopup(nsnull); } NS_RELEASE(global); }